Re: [PATCH] Define [range.cmp] comparisons for C++20

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Define [range.cmp] comparisons for C++20

Jonathan Wakely-4
On Wed, 23 Oct 2019 at 00:33, Tam S. B. <[hidden email]> wrote:

>
> > commit b948d3f92d7bbe4d53237cb20ff40a15fa123988
> > Author: Jonathan Wakely <[hidden email]>
> > Date:   Thu Oct 17 15:20:38 2019 +0100
> >
> >     Define [range.cmp] comparisons for C++20
> >
> >     Define std::identity, std::ranges::equal_to, std::ranges::not_equal_to,
> >     std::ranges::greater, std::ranges::less, std::ranges::greater_equal and
> >     std::ranges::less_equal.
> >
> >             * include/Makefile.am: Add new header.
> >             * include/Makefile.in: Regenerate.
> >             * include/bits/range_cmp.h: New header for C++20 function objects.
> >             * include/std/functional: Include new header.
> >             * testsuite/20_util/function_objects/identity/1.cc: New test.
> >             * testsuite/20_util/function_objects/range.cmp/equal_to.cc: New test.
> >             * testsuite/20_util/function_objects/range.cmp/greater.cc: New test.
> >             * testsuite/20_util/function_objects/range.cmp/greater_equal.cc: New
> >             test.
> >             * testsuite/20_util/function_objects/range.cmp/less.cc: New test.
> >             * testsuite/20_util/function_objects/range.cmp/less_equal.cc: New test.
> >             * testsuite/20_util/function_objects/range.cmp/not_equal_to.cc: New
> >             test.
> >
> > diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
> > index 35ee3cfcd34..9ff12f10fb1 100644
> > --- a/libstdc++-v3/include/Makefile.am
> > +++ b/libstdc++-v3/include/Makefile.am
> > @@ -152,6 +152,7 @@ bits_headers = \
> >       ${bits_srcdir}/random.h \
> >       ${bits_srcdir}/random.tcc \
> >       ${bits_srcdir}/range_access.h \
> > +     ${bits_srcdir}/range_cmp.h \
> >       ${bits_srcdir}/refwrap.h \
> >       ${bits_srcdir}/regex.h \
> >       ${bits_srcdir}/regex.tcc \
> > diff --git a/libstdc++-v3/include/bits/range_cmp.h b/libstdc++-v3/include/bits/range_cmp.h
> > new file mode 100644
> > index 00000000000..3e5bb8847ab
> > --- /dev/null
> > +++ b/libstdc++-v3/include/bits/range_cmp.h
> > @@ -0,0 +1,179 @@
> > +// Concept-constrained comparison implementations -*- C++ -*-
> > +
> > +// Copyright (C) 2019 Free Software Foundation, Inc.
> > +//
> > +// This file is part of the GNU ISO C++ Library.  This library is free
> > +// software; you can redistribute it and/or modify it under the
> > +// terms of the GNU General Public License as published by the
> > +// Free Software Foundation; either version 3, or (at your option)
> > +// any later version.
> > +
> > +// This library is distributed in the hope that it will be useful,
> > +// but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +// GNU General Public License for more details.
> > +
> > +// Under Section 7 of GPL version 3, you are granted additional
> > +// permissions described in the GCC Runtime Library Exception, version
> > +// 3.1, as published by the Free Software Foundation.
> > +
> > +// You should have received a copy of the GNU General Public License and
> > +// a copy of the GCC Runtime Library Exception along with this program;
> > +// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
> > +// <http://www.gnu.org/licenses/>.
> > +
> > +/** @file bits/ranges_function.h
>
> This does not match the actual filename. Seems like a typo?

Yes, I renamed the file and didn't fix the comment. It's already fixed
locally and will be committed with the next round of changes (probably
today).

> > + *  This is an internal header file, included by other library headers.
> > + *  Do not attempt to use it directly. @headername{functional}
> > + */
> > +
> > +#ifndef _RANGE_CMP_H
> > +#define _RANGE_CMP_H 1
> > +
> > +#if __cplusplus > 201703L
> > +# include <bits/move.h>
> > +# include <concepts>
> > +
> > +namespace std _GLIBCXX_VISIBILITY(default)
> > +{
> > +_GLIBCXX_BEGIN_NAMESPACE_VERSION
> > +
> > +  struct __is_transparent; // not defined
> > +
> > +  // Define std::identity here so that <iterator> and <ranges>
> > +  // don't need to include <bits/stl_function.h> to get it.
> > +
> > +  /// [func.identity] The identity function.
> > +  struct identity
> > +  {
> > +    template<typename _Tp>
> > +      constexpr _Tp&&
> > +      operator()(_Tp&& __t) const noexcept
> > +      { return std::forward<_Tp>(__t); }
> > +
> > +    using is_transparent = __is_transparent;
> > +  };
> > +
> > +namespace ranges
> > +{
> > +  namespace __detail
> > +  {
> > +    // BUILTIN-PTR-CMP(T, ==, U)
> > +    template<typename _Tp, typename _Up>
> > +      concept __eq_builtin_ptr_cmp
> > +     = convertible_to<_Tp, const volatile void*>
> > +       && convertible_to<_Up, const volatile void*>
> > +       && (! requires(_Tp&& __t, _Up&& __u)
>
> The use of concepts is causing `#include <functional>` to break on clang.

OK, thanks, I'll guard it with #if.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Define [range.cmp] comparisons for C++20

Jonathan Wakely-3
On 23/10/19 08:08 +0100, Jonathan Wakely wrote:
>On Wed, 23 Oct 2019 at 00:33, Tam S. B. <[hidden email]> wrote:
>> The use of concepts is causing `#include <functional>` to break on clang.
>
>OK, thanks, I'll guard it with #if.

Fixed on trunk with this patch. My Clang 7.0.1 still can't compile current
trunk though, because we now have a constexpr destructor on
std::allocator.

Thanks for the report.


patch.txt (1K) Download Attachment