C++ Logo

std-proposals

Advanced search

Re: Implementation Section of Class Definition

From: Andrew Tomazos <andrewtomazos_at_[hidden]>
Date: Tue, 16 Jul 2019 06:36:06 +1000
This thread isn't actually supposed to be about namespace templates. :)

But anyway, here is a live link to my current partial draft:
https://docs.google.com/document/d/1Pg83Tkc5sH7LUAAfk-FpYbEhBYZIdVUzps_Dypv_05Q/edit?usp=sharing

It's a work in-progress.

On Tue, Jul 16, 2019 at 6:22 AM Daniel Gutson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Re-sending due to email issues.
>
> El dom., 14 jul. 2019 04:59, Daniel Gutson <danielgutson_at_[hidden]>
> escribió:
>
>>
>>
>> El dom., 14 jul. 2019 04:27, Andrew Tomazos <andrewtomazos_at_[hidden]>
>> escribió:
>>
>>> I've been working on a proposal for namespace templates as motivated by
>>> what I call the library configuration problem.
>>>
>>
> This comes from a 5 years old discussion I started where you participated:
>
> https://groups.google.com/a/isocpp.org/forum/m/#!topic/std-proposals/8IDbb1L5_UA
>
> There are evidences of people asking about this at least since 2010:
> https://stackoverflow.com/questions/3319503/templating-a-namespace
>
> IMVHO is important to provide some historical context.
>
> So, I'm lost and didn't follow up since then, could you pr Jake please
> tell me the status of that topic? Jake Arkinstall had a draft IIRC.
>
>
>>
>>
>> One of the things that came up during discussions was a use case around
>>> out-of-class definitions in a class template. I don't currently see a
>>> unified solution to both things, however I have come up with an idea for a
>>> feature that solves the out-of-class definitions problem.
>>>
>>> Let us first state what the out-of-class definition problem is.
>>>
>>> When you define a class template you have two choices. Either you
>>> define the members within the class template Java-style:
>>>
>>> template<typename T>
>>> class C {
>>> public:
>>> void f() { /* do stuff */ }
>>> };
>>>
>>> or you define the members outside the class template:
>>>
>>> template<typename T>
>>> class C {
>>> public:
>>> void f();
>>> };
>>>
>>> template<typename T>
>>> void C<T>::f() { /* do stuff */ }
>>>
>>> The problem with defining them inside the class is that it hampers
>>> readability as the definitions clutter the interface.
>>>
>>> The problem with defining them outside the class is that it requires
>>> boilerplate DRY violations to repeat the (potentially lengthy) template
>>> head and class name for each definition.
>>>
>>> So my idea would be to introduce a new implementation section of a class
>>> definition that may only define previously declared member entities. The
>>> section allows the best of both worlds. You can define the entities
>>> in-line in the class, but not clutter the separate interface section:
>>>
>>> template<typename T>
>>> class C {
>>> public:
>>> void f();
>>> implementation:
>>> void f() { /* do stuff */ }
>>> };
>>>
>>> The access level (public, private, protected) of the members defined in
>>> the implementation section is taken from their original declaration.
>>>
>>> Thoughts? Is this worth pursuing?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "ISO C++ Standard - Future Proposals" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to std-proposals+unsubscribe_at_isocpp.org.
>>> To view this discussion on the web visit
>>> https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KH%2B4HUh4x42xchBL3nEC-7KRZT%2B6kHb5WByfsvPm6iUn_A%40mail.gmail.com
>>> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KH%2B4HUh4x42xchBL3nEC-7KRZT%2B6kHb5WByfsvPm6iUn_A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2019-07-15 15:38:14