C++ Logo

std-proposals

Advanced search

Re: Make class template parameters available externally

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Thu, 31 Oct 2019 12:22:54 +0300
On 2019-10-31 03:09, Sebastian Büttner via Std-Proposals wrote:
> I don't think that the meaning is consistent here. Declaring something
> private isn't the same as not declaring it at all.
>
> Also: how is declaring a template parameter private/public affecting
> inheritance? Is the behavior consistent with class member access
> control? Is a private declared template parameter of class B not
> accessible in a derived class D? Can I declare a template parameter
> protected then?
>
> template<public class first_param, private class second_param>
> class B
> { /* ... */ };
>
> class D: public B
> {
> // is first_param accessible here? is second_param accessible or not?
> };
>
> If you give this feature the same name as class member access control
> users will think likely expect the same behavior and every unreasonable
> deviation will be observed as inconsistency.

The behavior can be made exactly consistent with access control - the
keywords designate the access mode of the members introduced by template
parameters.

   template<
     public typename A,
     protected int B,
     private template< typename > class C
>
   struct X {};

is equivalent to

   template<
     typename A,
     int B,
     template< typename > class C
>
   struct X
   {
   public:
     typedef A A;

   protected:
     static constexpr int B = B;

   private:
     template< typename _ >
     using C = C< _ >;
   };

There's little use in "private" specifier, but conceptually this looks
sound.

> On 31.10.19 00:56, Jake Arkinstall wrote:
>> There are keywords with a consistent meaning: public and private. I'd
>> prefer those.
>>
>> On Wed, 30 Oct 2019, 23:43 Sebastian Büttner via Std-Proposals,
>> <std-proposals_at_[hidden]
>> <mailto:std-proposals_at_[hidden]>> wrote:
>>
>> I very much dislike reusing existing keywords with established
>> meaning
>> for an entirely different purpose.
>> Even though i suspect that this is just a strawmen syntax i don't
>> think
>> on the other hand that the suggestion is important enough to
>> justify a
>> new keyword.
>>
>> Sebastian
>>
>> On 30.10.19 23:48, Bjorn Reese via Std-Proposals wrote:
>> > On 10/30/19 10:49 PM, Ville Voutilainen via Std-Proposals wrote:
>> >
>> >> If I then _don't_ want to expose such a template parameter
>> name, what
>> >> do I do?
>> >
>> > The proposal could make it opt-in instead of opt-out. That would not
>> > expose existing template parameters without the consent of the
>> > template author. For example:
>> >
>> > template <explicit class value_type,
>> > explicit class allocator_type>
>> > struct vector {
>> > };
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden] <mailto:Std-Proposals_at_[hidden]>
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>

Received on 2019-10-31 04:25:14