public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural
@ 2023-04-24 16:23 Patrick Palka
  2023-08-16 16:06 ` Patrick Palka
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2023-04-24 16:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++, Patrick Palka

This patch makes these integer-class type structural types by changing
their private data members into public ones, which allows them to be
used as NTTP types.  I'm not sure if this is required by the standard
but it seems handy.

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

libstdc++-v3/ChangeLog:

	* include/bits/max_size_type.h (__max_size_type::_M_val): Make
	public instead of private.
	(__max_size_type::_M_msb): Likewise.
	(__max_diff_type::_M_rep): Likewise.
	* testsuite/std/ranges/iota/max_size_type.cc: Verify
	__max_diff_type and __max_size_type are structural.
---
 libstdc++-v3/include/bits/max_size_type.h               | 4 ++--
 libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h
index 4796135d073..d6705bbe4c8 100644
--- a/libstdc++-v3/include/bits/max_size_type.h
+++ b/libstdc++-v3/include/bits/max_size_type.h
@@ -423,10 +423,11 @@ namespace ranges
       using __rep = unsigned long long;
 #endif
       static constexpr size_t _S_rep_bits = sizeof(__rep) * __CHAR_BIT__;
-    private:
+
       __rep _M_val = 0;
       unsigned _M_msb:1 = 0;
 
+    private:
       constexpr explicit
       __max_size_type(__rep __val, int __msb) noexcept
 	: _M_val(__val), _M_msb(__msb)
@@ -750,7 +751,6 @@ namespace ranges
       { return !(__l < __r); }
 #endif
 
-    private:
       __max_size_type _M_rep = 0;
 
       friend class __max_size_type;
diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
index 985acd5a803..9afd05d5acf 100644
--- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
+++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
@@ -400,6 +400,13 @@ static_assert(max_diff_t(max_size_t(1)
 			 << (numeric_limits<max_size_t>::digits-1))
 	      == numeric_limits<max_diff_t>::min());
 
+// Verify that the types are structural types and can therefore be used
+// as NTTP types.
+template<max_size_t V> struct Su { static_assert(V*V == V+132); };
+template<max_diff_t V> struct Ss { static_assert(V*V == V+132); };
+template struct Su<12>;
+template struct Ss<12>;
+
 int
 main()
 {
-- 
2.40.0.374.g7580f92ffa


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural
  2023-04-24 16:23 [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural Patrick Palka
@ 2023-08-16 16:06 ` Patrick Palka
  2023-08-16 17:30   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2023-08-16 16:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: libstdc++

On Mon, Apr 24, 2023 at 12:23 PM Patrick Palka <ppalka@redhat.com> wrote:
>
> This patch makes these integer-class type structural types by changing
> their private data members into public ones, which allows them to be
> used as NTTP types.  I'm not sure if this is required by the standard
> but it seems handy.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

Ping

>
> libstdc++-v3/ChangeLog:
>
>         * include/bits/max_size_type.h (__max_size_type::_M_val): Make
>         public instead of private.
>         (__max_size_type::_M_msb): Likewise.
>         (__max_diff_type::_M_rep): Likewise.
>         * testsuite/std/ranges/iota/max_size_type.cc: Verify
>         __max_diff_type and __max_size_type are structural.
> ---
>  libstdc++-v3/include/bits/max_size_type.h               | 4 ++--
>  libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 7 +++++++
>  2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h
> index 4796135d073..d6705bbe4c8 100644
> --- a/libstdc++-v3/include/bits/max_size_type.h
> +++ b/libstdc++-v3/include/bits/max_size_type.h
> @@ -423,10 +423,11 @@ namespace ranges
>        using __rep = unsigned long long;
>  #endif
>        static constexpr size_t _S_rep_bits = sizeof(__rep) * __CHAR_BIT__;
> -    private:
> +
>        __rep _M_val = 0;
>        unsigned _M_msb:1 = 0;
>
> +    private:
>        constexpr explicit
>        __max_size_type(__rep __val, int __msb) noexcept
>         : _M_val(__val), _M_msb(__msb)
> @@ -750,7 +751,6 @@ namespace ranges
>        { return !(__l < __r); }
>  #endif
>
> -    private:
>        __max_size_type _M_rep = 0;
>
>        friend class __max_size_type;
> diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> index 985acd5a803..9afd05d5acf 100644
> --- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> +++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> @@ -400,6 +400,13 @@ static_assert(max_diff_t(max_size_t(1)
>                          << (numeric_limits<max_size_t>::digits-1))
>               == numeric_limits<max_diff_t>::min());
>
> +// Verify that the types are structural types and can therefore be used
> +// as NTTP types.
> +template<max_size_t V> struct Su { static_assert(V*V == V+132); };
> +template<max_diff_t V> struct Ss { static_assert(V*V == V+132); };
> +template struct Su<12>;
> +template struct Ss<12>;
> +
>  int
>  main()
>  {
> --
> 2.40.0.374.g7580f92ffa
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural
  2023-08-16 16:06 ` Patrick Palka
@ 2023-08-16 17:30   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-08-16 17:30 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, libstdc++

On Wed, 16 Aug 2023 at 17:07, Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On Mon, Apr 24, 2023 at 12:23 PM Patrick Palka <ppalka@redhat.com> wrote:
> >
> > This patch makes these integer-class type structural types by changing
> > their private data members into public ones, which allows them to be
> > used as NTTP types.  I'm not sure if this is required by the standard
> > but it seems handy.
> >
> > Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
>
> Ping


I'm not sure about this one. I am pretty sure it's not required, and
I'm not sure it's needed.

Do we have a use for it ourselves? Users shouldn't be using this type
directly, or relying on properties that the standard doesn't specify,
so I don't think they should be using it as a structural type.


>
> >
> > libstdc++-v3/ChangeLog:
> >
> >         * include/bits/max_size_type.h (__max_size_type::_M_val): Make
> >         public instead of private.
> >         (__max_size_type::_M_msb): Likewise.
> >         (__max_diff_type::_M_rep): Likewise.
> >         * testsuite/std/ranges/iota/max_size_type.cc: Verify
> >         __max_diff_type and __max_size_type are structural.
> > ---
> >  libstdc++-v3/include/bits/max_size_type.h               | 4 ++--
> >  libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 7 +++++++
> >  2 files changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h
> > index 4796135d073..d6705bbe4c8 100644
> > --- a/libstdc++-v3/include/bits/max_size_type.h
> > +++ b/libstdc++-v3/include/bits/max_size_type.h
> > @@ -423,10 +423,11 @@ namespace ranges
> >        using __rep = unsigned long long;
> >  #endif
> >        static constexpr size_t _S_rep_bits = sizeof(__rep) * __CHAR_BIT__;
> > -    private:
> > +
> >        __rep _M_val = 0;
> >        unsigned _M_msb:1 = 0;
> >
> > +    private:
> >        constexpr explicit
> >        __max_size_type(__rep __val, int __msb) noexcept
> >         : _M_val(__val), _M_msb(__msb)
> > @@ -750,7 +751,6 @@ namespace ranges
> >        { return !(__l < __r); }
> >  #endif
> >
> > -    private:
> >        __max_size_type _M_rep = 0;
> >
> >        friend class __max_size_type;
> > diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> > index 985acd5a803..9afd05d5acf 100644
> > --- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> > +++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc
> > @@ -400,6 +400,13 @@ static_assert(max_diff_t(max_size_t(1)
> >                          << (numeric_limits<max_size_t>::digits-1))
> >               == numeric_limits<max_diff_t>::min());
> >
> > +// Verify that the types are structural types and can therefore be used
> > +// as NTTP types.
> > +template<max_size_t V> struct Su { static_assert(V*V == V+132); };
> > +template<max_diff_t V> struct Ss { static_assert(V*V == V+132); };
> > +template struct Su<12>;
> > +template struct Ss<12>;
> > +
> >  int
> >  main()
> >  {
> > --
> > 2.40.0.374.g7580f92ffa
> >
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-16 17:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-24 16:23 [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural Patrick Palka
2023-08-16 16:06 ` Patrick Palka
2023-08-16 17:30   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).