Topic: Templated namespaces/scope


Author: Miguel Martin <deeharok@gmail.com>
Date: Tue, 2 Dec 2014 04:01:06 -0800 (PST)
Raw View
------=_Part_1699_11822398.1417521666829
Content-Type: multipart/alternative;
 boundary="----=_Part_1700_1130547662.1417521666829"

------=_Part_1700_1130547662.1417521666829
Content-Type: text/plain; charset=UTF-8

Hi there, I'm new here, so hello :)

I think that template scope/namespaces would be a good addition to further
versions of C++. I'm not sure if this has been previously proposed, and I
wouldn't be surprised if it hasn't. The main point of this idea is for less
boiler plate to be present within code. Take the following example:

template <class T>
struct Vec2
{
       T x, y;


       Vec2(T x = T(), T y= T());

       Vec2<T> abs() const;
       T length() const;
       void normalize();
       // etc.
};

Now to implement this class (outside), you would have to place template<class
T> before every function/constructor/static member variable that is
declared within the class's interface. So my solution is to simply allow
for a scope for template parameters to be used, such as:

template <class T>
namespace
{
      Vec2<T> Vec2<T>::abs() const
      {
           return Vec2<T>{std::abs(x), std::abs(y)};
      }

      T Vec2<T>::length() const
      {
          return std::sqrt(x*x + y*y);
      }


      void Vec2<T>::normalize()
      {
          auto len = length();
          x /= len;
          y /= len;
      }


       // etc.
}


*Note: *
I've used the namespace keyword to re-use the keyword, instead of making
another, although the scope operators { and } could probably be used.
However, I feel that if you wanted to name the namespace, e.g.
Math<double>::Pi, then you should be able to.

Un-related: There is actually still quite a bit of boiler plate still
present and that name is Vec2<T>:: which is something I want to discuss
into another proposal idea.

To re-iterate, consider what we presently have: we have to place a template
<class T> every time we want to implement a function/ctor/static-member of
the class Vec2<T>, as it as a template class.

Now the two issues that I imagine people would be thinking are:

1. Why not just implement it within the class itself? I would say that this
is the most common work-around to the current "predicament", in the scene
that it is common C++ convention to separate interface and implementation.
Sure, you could mention that templates require to be defined in the header
anyway, so no harm is done, but if modules come then this could possibly
not be the case (I'm not actually sure about this). Also, there are several
examples of this mass boiler plate occurring in production code, for
example within SFML and it's template classes. They separate the
implementation to a .inl file and just #include it within the header of the
declaration (e.g. Vector2<T> .hpp
<https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.hpp>,
..inl
<https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.inl>
).

2. It's not that much boiler plate code you have to write, or rather it's
not much of a hassle to do it. Sure this may be the case for *most*
classes. However, consider the case in which we wish to add or remove some
template parameters; we have to update a lot of sections than necessary,
just to make the code build. For example: consider the previous example,
except we turn Vec2<T> into Vec<T, Size> where Size is an integer
describing the dimension of the vector data structure. We
actually will still have to update a lot of sections of our code, and that
is adding , Size to everywhere we wrote Vec<T>:: (I want to discuss a
solution to this in another proposal idea, as I mentioned above), but the
amount of boiler plate has still been greatly reduced.

Another Example

template <class T>
namespace math_constants
{
    namespace detail
    {
        constexpr T compute_pi();
    }


    constexpr const T pi = detail::compute_pi();
    // etc.
}

//...

int main()
{
    using namespace math_constants<double>;

    std::cout << pi << '\n';
}

Note that this particular example could be implemented within a struct in
the current standard.

I would really like to hear your thoughts about this idea and any
constructive criticism :) Thanks.

--

---
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@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_1700_1130547662.1417521666829
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div>Hi there, I'm new here, so hello :)</div><div><b=
r></div><div>I think that template scope/namespaces would be a good additio=
n to further versions of C++. I'm not sure if this has been previously prop=
osed, and I wouldn't be surprised if it hasn't. The main point of this idea=
 is for less boiler plate to be present within code. Take the following exa=
mple:</div><div><br></div><div class=3D"prettyprint" style=3D"border: 1px s=
olid rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, =
250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">template</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">V=
ec2</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbs=
p; &nbsp;T x</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> y</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br>&nbsp; &nbsp=
; &nbsp; &nbsp;</span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Vec2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T x </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(),</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> T y</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">());</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;</s=
pan><span style=3D"color: #606;" class=3D"styled-by-prettify">Vec2</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> abs</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>&nbsp; &nbsp; &nbsp; &nbsp;T length</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> normalize</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color: #800;" clas=
s=3D"styled-by-prettify">// etc.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">};</span></div></code></div><div><br></div><div>Now to im=
plement this class (outside), you would have to place <font face=3D"courier=
 new, monospace">template&lt;class T&gt;</font> before every function/const=
ructor/static member variable that is declared within the class's interface=
.. So my solution is to simply allow for a scope for template parameters to =
be used, such as:</div><div><br></div><div class=3D"prettyprint" style=3D"b=
order: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-colo=
r: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subpretty=
print"><span style=3D"color: #008;" class=3D"styled-by-prettify">template</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">class</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">namespace</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; &nbsp; &nbsp; </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Vec2</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Vec2</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">&gt;::</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">abs</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>&nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">return</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Vec2</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&gt;{</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">abs=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">x</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">),</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">abs</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">y</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)};</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; T </span><span style=3D"co=
lor: #606;" class=3D"styled-by-prettify">Vec2</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">length</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">sqrt</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">x</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">*</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">x </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> y</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">*</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">y</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>&nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br><br><br>&nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-b=
y-prettify">Vec2</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;::</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">normalize</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbs=
p; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp=
; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> len </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> leng=
th</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbs=
p; &nbsp; &nbsp; &nbsp; x </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">/=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> len</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&=
nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">/=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> len</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>&nbsp; &nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"col=
or: #800;" class=3D"styled-by-prettify">// etc.</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">}</span></div></code></div><div><br></div><d=
iv><br></div><div><b>Note:&nbsp;</b></div><div>I've used the namespace keyw=
ord to re-use the keyword, instead of making another, although the scope op=
erators { and } could probably be used. However, I feel that if you wanted =
to name the namespace, e.g. Math&lt;double&gt;::Pi, then you should be able=
 to.</div><div><br></div><div><font color=3D"#666666">Un-related: There is =
actually still quite a bit of boiler plate still present and that name is <=
font face=3D"courier new, monospace">Vec2&lt;T&gt;::</font> which is someth=
ing I want to discuss into another proposal idea.</font></div><div><br></di=
v><div>To re-iterate, consider what we presently have: we have to place a t=
emplate &lt;class T&gt; every time we want to implement a function/ctor/sta=
tic-member of the class <font face=3D"courier new, monospace">Vec2&lt;T&gt;=
</font>, as it as a template class.</div><div><br></div><div>Now the two is=
sues that I imagine people would be thinking are:</div><div><br></div><div>=
1. Why not just implement it within the class itself? I would say that this=
 is the most common work-around to the current "predicament", in the scene =
that it is common C++ convention to separate interface and implementation. =
Sure, you could mention that templates require to be defined in the header =
anyway, so no harm is done, but if modules come then this could possibly no=
t be the case (I'm not actually sure about this). Also, there are several e=
xamples of this mass boiler plate occurring in production code, for example=
 within SFML and it's template classes. They separate the implementation to=
 a <font face=3D"courier new, monospace">.inl </font>file and just <font fa=
ce=3D"courier new, monospace">#include</font> it within the header of the d=
eclaration (e.g. Vector2&lt;T&gt; <a href=3D"https://github.com/LaurentGomi=
la/SFML/blob/master/include/SFML/System/Vector2.hpp">.hpp</a>, <a href=3D"h=
ttps://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector=
2.inl">.inl</a>).</div><div><br></div><div>2. It's not that much boiler pla=
te code you have to write, or rather it's not much of a hassle to do it. Su=
re this may be the case for *most* classes. However, consider the case in w=
hich we wish to add or remove some template parameters; we have to update a=
 lot of sections than necessary, just to make the code build. For example: =
consider the previous example, except we turn <font face=3D"courier new, mo=
nospace">Vec2&lt;T&gt;</font> into <font face=3D"courier new, monospace">Ve=
c&lt;T, Size&gt;</font> where <font face=3D"courier new, monospace">Size</f=
ont> is an integer describing the dimension of the vector data structure. W=
e</div><div>actually will still have to update a lot of sections of our cod=
e, and that is adding , Size to everywhere we wrote <font face=3D"courier n=
ew, monospace">Vec&lt;T&gt;:: </font>(I want to discuss a solution to this =
in another proposal idea, as I mentioned above), but the amount of boiler p=
late has still been greatly reduced.</div><div><span style=3D"font-size: la=
rge;"><br></span></div><div><span style=3D"font-size: large;">Another Examp=
le</span><br></div><div><br></div><div></div></div><div class=3D"prettyprin=
t" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; ba=
ckground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">template</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">namespace</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> math_constants<br></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">namespace</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> detail<br>&nbsp; &nbsp; </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
expr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T com=
pute_pi</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br><br=
>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T pi </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> detail</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">compute_pi</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// etc.</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">//...</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"sty=
led-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> main</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">using</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">namespace</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> math_constants</span><sp=
an style=3D"color: #080;" class=3D"styled-by-prettify">&lt;double</span><fo=
nt color=3D"#666600"><span style=3D"color: #080;" class=3D"styled-by-pretti=
fy">&gt;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></s=
pan></font><span style=3D"color: #000;" class=3D"styled-by-prettify">&nbsp;=
 &nbsp; std</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">cout </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> pi </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #080;" class=3D"styled-by-prettify">'\n'</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span></div></code></div><div><br></div><div>Note=
 that this particular example could be implemented within a struct in the c=
urrent standard.<br></div><div><br></div><div>I would really like to hear y=
our thoughts about this idea and any constructive criticism :) Thanks.</div=
></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1700_1130547662.1417521666829--
------=_Part_1699_11822398.1417521666829--

.


Author: David Krauss <potswa@gmail.com>
Date: Tue, 2 Dec 2014 20:10:14 +0800
Raw View
--Apple-Mail=_DA8BD36D-BA91-4407-90F0-2538195D0D50
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


On 2014=E2=80=9312=E2=80=9302, at 8:01 PM, Miguel Martin <deeharok@gmail.co=
m> wrote:

> I think that template scope/namespaces would be a good addition to furthe=
r versions of C++.

One way to realize this might be to specify that every contained declaratio=
n becomes templated: classes become class templates, variables become varia=
ble templates, and typedefs become alias templates.

I don=E2=80=99t think we want to adjust the rules for template definitions =
and linkage. The contents of the namespace template would all be defined in=
 the header file. If modules map header files to something that can be tran=
slated once, then the problem is already solved.

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_DA8BD36D-BA91-4407-90F0-2538195D0D50
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014=
=E2=80=9312=E2=80=9302, at 8:01 PM, Miguel Martin &lt;<a href=3D"mailto:dee=
harok@gmail.com">deeharok@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-=
interchange-newline"><blockquote type=3D"cite"><span style=3D"font-family: =
Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-=
weight: normal; letter-spacing: normal; line-height: normal; orphans: auto;=
 text-align: start; text-indent: 0px; text-transform: none; white-space: no=
rmal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; floa=
t: none; display: inline !important;">I think that template scope/namespace=
s would be a good addition to further versions of C++.</span></blockquote><=
/div><br><div>One way to realize this might be to specify that every contai=
ned declaration becomes templated: classes become class templates, variable=
s become variable templates, and typedefs become alias templates.</div><div=
><br></div><div>I don=E2=80=99t think we want to adjust the rules for templ=
ate definitions and linkage. The contents of the namespace template would a=
ll be defined in the header file. If modules map header files to something =
that can be translated once, then the problem is already solved.</div></bod=
y></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_DA8BD36D-BA91-4407-90F0-2538195D0D50--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Tue, 2 Dec 2014 15:31:04 +0200
Raw View
On 2 December 2014 at 14:01, Miguel Martin <deeharok@gmail.com> wrote:
> Now the two issues that I imagine people would be thinking are:
> 2. It's not that much boiler plate code you have to write, or rather it's
> not much of a hassle to do it. Sure this may be the case for *most* classes.
> However, consider the case in which we wish to add or remove some template
> parameters; we have to update a lot of sections than necessary, just to make
> the code build. For example: consider the previous example, except we turn
> Vec2<T> into Vec<T, Size> where Size is an integer describing the dimension
> of the vector data structure. We
> actually will still have to update a lot of sections of our code, and that
> is adding , Size to everywhere we wrote Vec<T>:: (I want to discuss a
> solution to this in another proposal idea, as I mentioned above), but the
> amount of boiler plate has still been greatly reduced.


I fail to see what part of such an edit is difficult to do. I am very
much a fan of
reducing boilerplate, but I don't think this idea has a good enough cost/benefit
ratio if that sort of refactorings are its main motivation. If you
want to suggest
that the shortcutting/grouping it provides is a readability improvement, I must
ask why templates need such shortcutting more than other language facilities.

It's been suggested many times that C++ should have a "with"-control construct.
That has failed every time. I don't know whether it's ever been
suggested to have a
"static with" that shortcuts a class or a class template, but I would doubt its
success as well since it's going to be a relatively large and in some sense
inconsistent addition to the language.

I can certainly alleviate the perceived problem by declaring a nested class
(template) inside the main class (template), and defining that class (template)
outside the main one, and then writing the member function definitions
of that class (template) inside its definition. I can alleviate the problem by
not having so many members for the class that its maintenance becomes
burdensome.

The motivation for this proposal seems weak.

--

---
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@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Tue, 2 Dec 2014 14:39:30 +0000
Raw View
+1, except I would omit the namespace' & <T>.

Re: the first potential criticism, inclass code has inline semantics.

On 12/2/14, Ville Voutilainen <ville.voutilainen@gmail.com> wrote:
> On 2 December 2014 at 14:01, Miguel Martin <deeharok@gmail.com> wrote:
>> Now the two issues that I imagine people would be thinking are:
>> 2. It's not that much boiler plate code you have to write, or rather it's
>> not much of a hassle to do it. Sure this may be the case for *most*
>> classes.
>> However, consider the case in which we wish to add or remove some
>> template
>> parameters; we have to update a lot of sections than necessary, just to
>> make
>> the code build. For example: consider the previous example, except we
>> turn
>> Vec2<T> into Vec<T, Size> where Size is an integer describing the
>> dimension
>> of the vector data structure. We
>> actually will still have to update a lot of sections of our code, and
>> that
>> is adding , Size to everywhere we wrote Vec<T>:: (I want to discuss a
>> solution to this in another proposal idea, as I mentioned above), but the
>> amount of boiler plate has still been greatly reduced.
>
>
> I fail to see what part of such an edit is difficult to do. I am very
> much a fan of
> reducing boilerplate, but I don't think this idea has a good enough
> cost/benefit
> ratio if that sort of refactorings are its main motivation. If you
> want to suggest
> that the shortcutting/grouping it provides is a readability improvement, I
> must
> ask why templates need such shortcutting more than other language
> facilities.
>
> It's been suggested many times that C++ should have a "with"-control
> construct.
> That has failed every time. I don't know whether it's ever been
> suggested to have a
> "static with" that shortcuts a class or a class template, but I would doubt
> its
> success as well since it's going to be a relatively large and in some sense
> inconsistent addition to the language.
>
> I can certainly alleviate the perceived problem by declaring a nested class
> (template) inside the main class (template), and defining that class
> (template)
> outside the main one, and then writing the member function definitions
> of that class (template) inside its definition. I can alleviate the problem
> by
> not having so many members for the class that its maintenance becomes
> burdensome.
>
> The motivation for this proposal seems weak.
>
> --
>
> ---
> 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@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--

---
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@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: snk_kid <korcan.hussein@googlemail.com>
Date: Tue, 2 Dec 2014 08:03:43 -0800 (PST)
Raw View
------=_Part_2423_1910832389.1417536223832
Content-Type: multipart/alternative;
 boundary="----=_Part_2424_1889504685.1417536223832"

------=_Part_2424_1889504685.1417536223832
Content-Type: text/plain; charset=UTF-8

How would this work with mixing parameterized and non-parameterized
namespaces with the same name (e.g. std) and in terms of name mangling? how
does it integrate with the proposed C++ modules?

Perhaps instead of parametrized namespaces, extend the modules proposal to
support *parameterized modules* kind of like in the SML programming
language (which has the "Ferrari" of module systems in the PLT world),
check *module functors* in SML like here
<http://www.cs.cornell.edu/Courses/cs3110/2011sp/lectures/lec09-functors/functors.htm>

I would much rather prefer that C++ templates are kept as simple as
possible and as there originally intended purpose which is for parametric
polymorphism and keep meta-programming as a separate properly designed
feature in C++ like as suggested here
<https://groups.google.com/a/isocpp.org/forum/?fromgroups=#!topic/std-proposals/MblNbx7xc94>
by extending constexpr functions beyond only compile-time functions to an
AST macro like system with support for used-defined C++ attributes and more
(check the link).

On Tuesday, December 2, 2014 12:01:06 PM UTC, Miguel Martin wrote:
>
> Hi there, I'm new here, so hello :)
>
> I think that template scope/namespaces would be a good addition to further
> versions of C++. I'm not sure if this has been previously proposed, and I
> wouldn't be surprised if it hasn't. The main point of this idea is for less
> boiler plate to be present within code. Take the following example:
>
> template <class T>
> struct Vec2
> {
>        T x, y;
>
>
>        Vec2(T x = T(), T y= T());
>
>        Vec2<T> abs() const;
>        T length() const;
>        void normalize();
>        // etc.
> };
>
> Now to implement this class (outside), you would have to place template<class
> T> before every function/constructor/static member variable that is
> declared within the class's interface. So my solution is to simply allow
> for a scope for template parameters to be used, such as:
>
> template <class T>
> namespace
> {
>       Vec2<T> Vec2<T>::abs() const
>       {
>            return Vec2<T>{std::abs(x), std::abs(y)};
>       }
>
>       T Vec2<T>::length() const
>       {
>           return std::sqrt(x*x + y*y);
>       }
>
>
>       void Vec2<T>::normalize()
>       {
>           auto len = length();
>           x /= len;
>           y /= len;
>       }
>
>
>        // etc.
> }
>
>
> *Note: *
> I've used the namespace keyword to re-use the keyword, instead of making
> another, although the scope operators { and } could probably be used.
> However, I feel that if you wanted to name the namespace, e.g.
> Math<double>::Pi, then you should be able to.
>
> Un-related: There is actually still quite a bit of boiler plate still
> present and that name is Vec2<T>:: which is something I want to discuss
> into another proposal idea.
>
> To re-iterate, consider what we presently have: we have to place a
> template <class T> every time we want to implement a
> function/ctor/static-member of the class Vec2<T>, as it as a template
> class.
>
> Now the two issues that I imagine people would be thinking are:
>
> 1. Why not just implement it within the class itself? I would say that
> this is the most common work-around to the current "predicament", in the
> scene that it is common C++ convention to separate interface and
> implementation. Sure, you could mention that templates require to be
> defined in the header anyway, so no harm is done, but if modules come then
> this could possibly not be the case (I'm not actually sure about this).
> Also, there are several examples of this mass boiler plate occurring in
> production code, for example within SFML and it's template classes. They
> separate the implementation to a .inl file and just #include it within
> the header of the declaration (e.g. Vector2<T> .hpp
> <https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.hpp>,
> .inl
> <https://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.inl>
> ).
>
> 2. It's not that much boiler plate code you have to write, or rather it's
> not much of a hassle to do it. Sure this may be the case for *most*
> classes. However, consider the case in which we wish to add or remove some
> template parameters; we have to update a lot of sections than necessary,
> just to make the code build. For example: consider the previous example,
> except we turn Vec2<T> into Vec<T, Size> where Size is an integer
> describing the dimension of the vector data structure. We
> actually will still have to update a lot of sections of our code, and that
> is adding , Size to everywhere we wrote Vec<T>:: (I want to discuss a
> solution to this in another proposal idea, as I mentioned above), but the
> amount of boiler plate has still been greatly reduced.
>
> Another Example
>
> template <class T>
> namespace math_constants
> {
>     namespace detail
>     {
>         constexpr T compute_pi();
>     }
>
>
>     constexpr const T pi = detail::compute_pi();
>     // etc.
> }
>
> //...
>
> int main()
> {
>     using namespace math_constants<double>;
>
>     std::cout << pi << '\n';
> }
>
> Note that this particular example could be implemented within a struct in
> the current standard.
>
> I would really like to hear your thoughts about this idea and any
> constructive criticism :) Thanks.
>

--

---
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@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_2424_1889504685.1417536223832
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">How would this work with mixing parameterized and non-para=
meterized namespaces with the same name (e.g. std) and in terms of name man=
gling? how does it integrate with the proposed C++ modules?<br><br>Perhaps =
instead of parametrized namespaces, extend the modules proposal to support =
<b>parameterized modules</b> kind of like in the SML programming language (=
which has the "Ferrari" of module systems in the PLT world), check <i>modul=
e functors</i> in SML like <a href=3D"http://www.cs.cornell.edu/Courses/cs3=
110/2011sp/lectures/lec09-functors/functors.htm">here</a><br><br>I would mu=
ch rather prefer that C++ templates are kept as simple as possible and as t=
here originally intended purpose which is for parametric polymorphism and k=
eep meta-programming as a separate properly designed feature in C++ like as=
 suggested <a href=3D"https://groups.google.com/a/isocpp.org/forum/?fromgro=
ups=3D#!topic/std-proposals/MblNbx7xc94">here</a> by extending constexpr fu=
nctions beyond only compile-time functions to an AST macro like system with=
 support for used-defined C++ attributes and more (check the link).<br><br>=
On Tuesday, December 2, 2014 12:01:06 PM UTC, Miguel Martin wrote:<blockquo=
te class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left:=
 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div><div>Hi there, I'=
m new here, so hello :)</div><div><br></div><div>I think that template scop=
e/namespaces would be a good addition to further versions of C++. I'm not s=
ure if this has been previously proposed, and I wouldn't be surprised if it=
 hasn't. The main point of this idea is for less boiler plate to be present=
 within code. Take the following example:</div><div><br></div><div style=3D=
"border:1px solid rgb(187,187,187);word-wrap:break-word;background-color:rg=
b(250,250,250)"><code><div><span style=3D"color:#008">template</span><span =
style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><span st=
yle=3D"color:#008">class</span><span style=3D"color:#000"> T</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br></span><span s=
tyle=3D"color:#008">struct</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#606">Vec2</span><span style=3D"color:#000"><br></span><span =
style=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &=
nbsp; &nbsp;T x</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> y</span><span style=3D"color:#660">;</span><span style=3D"color:#=
000"><br><br><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:#60=
6">Vec2</span><span style=3D"color:#660">(</span><span style=3D"color:#000"=
>T x </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"=
> T</span><span style=3D"color:#660">(),</span><span style=3D"color:#000"> =
T y</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
T</span><span style=3D"color:#660">());</span><span style=3D"color:#000"><b=
r>&nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span st=
yle=3D"color:#606">Vec2</span><span style=3D"color:#660">&lt;</span><span s=
tyle=3D"color:#000">T</span><span style=3D"color:#660">&gt;</span><span sty=
le=3D"color:#000"> abs</span><span style=3D"color:#660">()</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#008">const</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp;=
 &nbsp;T length</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">const</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp;=
</span><span style=3D"color:#008">void</span><span style=3D"color:#000"> no=
rmalize</span><span style=3D"color:#660">();</span><span style=3D"color:#00=
0"><br>&nbsp; &nbsp; &nbsp; &nbsp;</span><span style=3D"color:#800">// etc.=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">};<=
/span></div></code></div><div><br></div><div>Now to implement this class (o=
utside), you would have to place <font face=3D"courier new, monospace">temp=
late&lt;class T&gt;</font> before every function/constructor/static member =
variable that is declared within the class's interface. So my solution is t=
o simply allow for a scope for template parameters to be used, such as:</di=
v><div><br></div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:=
break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"col=
or:#008">template</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#008">class</span><span style=3D=
"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=3D"=
color:#000"><br></span><span style=3D"color:#008">namespace</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; </span><span style=3D"color:#606">=
Vec2</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000"=
>T</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">Vec2</span><span style=3D"color:#660">&lt=
;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;:=
:</span><span style=3D"color:#000">abs</span><span style=3D"color:#660">()<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">const</=
span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; </span><span style=
=3D"color:#660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp;=
 &nbsp; &nbsp; &nbsp;</span><span style=3D"color:#008">return</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#606">Vec2</span><span sty=
le=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">&gt;{</span><span style=3D"color:#000">std</span><span styl=
e=3D"color:#660">::</span><span style=3D"color:#000">abs</span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">x</span><span style=3D"c=
olor:#660">),</span><span style=3D"color:#000"> std</span><span style=3D"co=
lor:#660">::</span><span style=3D"color:#000">abs</span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#000">y</span><span style=3D"color:#66=
0">)};</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; </span><sp=
an style=3D"color:#660">}</span><span style=3D"color:#000"><br>&nbsp; &nbsp=
; &nbsp; <br>&nbsp; &nbsp; &nbsp; T </span><span style=3D"color:#606">Vec2<=
/span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</s=
pan><span style=3D"color:#660">&gt;::</span><span style=3D"color:#000">leng=
th</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </=
span><span style=3D"color:#008">const</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; &nbsp; </span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style=
=3D"color:#008">return</span><span style=3D"color:#000"> std</span><span st=
yle=3D"color:#660">::</span><span style=3D"color:#000">sqrt</span><span sty=
le=3D"color:#660">(</span><span style=3D"color:#000">x</span><span style=3D=
"color:#660">*</span><span style=3D"color:#000">x </span><span style=3D"col=
or:#660">+</span><span style=3D"color:#000"> y</span><span style=3D"color:#=
660">*</span><span style=3D"color:#000">y</span><span style=3D"color:#660">=
);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; </span><span s=
tyle=3D"color:#660">}</span><span style=3D"color:#000"><br><br><br>&nbsp; &=
nbsp; &nbsp; </span><span style=3D"color:#008">void</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#606">Vec2</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:=
#660">&gt;::</span><span style=3D"color:#000">normalize</span><span style=
=3D"color:#660">()</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp=
; </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color:#008">auto</=
span><span style=3D"color:#000"> len </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> length</span><span style=3D"color:#660">(=
);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
x </span><span style=3D"color:#660">/=3D</span><span style=3D"color:#000"> =
len</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br=
>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y </span><span style=3D"color:#660">/=
=3D</span><span style=3D"color:#000"> len</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; &nbsp; </span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br><br>&nbsp; &n=
bsp; &nbsp; &nbsp;</span><span style=3D"color:#800">// etc.</span><span sty=
le=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></cod=
e></div><div><br></div><div><br></div><div><b>Note:&nbsp;</b></div><div>I'v=
e used the namespace keyword to re-use the keyword, instead of making anoth=
er, although the scope operators { and } could probably be used. However, I=
 feel that if you wanted to name the namespace, e.g. Math&lt;double&gt;::Pi=
, then you should be able to.</div><div><br></div><div><font color=3D"#6666=
66">Un-related: There is actually still quite a bit of boiler plate still p=
resent and that name is <font face=3D"courier new, monospace">Vec2&lt;T&gt;=
::</font> which is something I want to discuss into another proposal idea.<=
/font></div><div><br></div><div>To re-iterate, consider what we presently h=
ave: we have to place a template &lt;class T&gt; every time we want to impl=
ement a function/ctor/static-member of the class <font face=3D"courier new,=
 monospace">Vec2&lt;T&gt;</font>, as it as a template class.</div><div><br>=
</div><div>Now the two issues that I imagine people would be thinking are:<=
/div><div><br></div><div>1. Why not just implement it within the class itse=
lf? I would say that this is the most common work-around to the current "pr=
edicament", in the scene that it is common C++ convention to separate inter=
face and implementation. Sure, you could mention that templates require to =
be defined in the header anyway, so no harm is done, but if modules come th=
en this could possibly not be the case (I'm not actually sure about this). =
Also, there are several examples of this mass boiler plate occurring in pro=
duction code, for example within SFML and it's template classes. They separ=
ate the implementation to a <font face=3D"courier new, monospace">.inl </fo=
nt>file and just <font face=3D"courier new, monospace">#include</font> it w=
ithin the header of the declaration (e.g. Vector2&lt;T&gt; <a href=3D"https=
://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.hp=
p" target=3D"_blank" onmousedown=3D"this.href=3D'https://www.google.com/url=
?q\75https%3A%2F%2Fgithub.com%2FLaurentGomila%2FSFML%2Fblob%2Fmaster%2Fincl=
ude%2FSFML%2FSystem%2FVector2.hpp\46sa\75D\46sntz\0751\46usg\75AFQjCNEmckFZ=
IyDt9Fy461B-gDU7VcmO_g';return true;" onclick=3D"this.href=3D'https://www.g=
oogle.com/url?q\75https%3A%2F%2Fgithub.com%2FLaurentGomila%2FSFML%2Fblob%2F=
master%2Finclude%2FSFML%2FSystem%2FVector2.hpp\46sa\75D\46sntz\0751\46usg\7=
5AFQjCNEmckFZIyDt9Fy461B-gDU7VcmO_g';return true;">.hpp</a>, <a href=3D"htt=
ps://github.com/LaurentGomila/SFML/blob/master/include/SFML/System/Vector2.=
inl" target=3D"_blank" onmousedown=3D"this.href=3D'https://www.google.com/u=
rl?q\75https%3A%2F%2Fgithub.com%2FLaurentGomila%2FSFML%2Fblob%2Fmaster%2Fin=
clude%2FSFML%2FSystem%2FVector2.inl\46sa\75D\46sntz\0751\46usg\75AFQjCNG7W9=
J6_OBPzMcUnCCatN0_03mIXA';return true;" onclick=3D"this.href=3D'https://www=
..google.com/url?q\75https%3A%2F%2Fgithub.com%2FLaurentGomila%2FSFML%2Fblob%=
2Fmaster%2Finclude%2FSFML%2FSystem%2FVector2.inl\46sa\75D\46sntz\0751\46usg=
\75AFQjCNG7W9J6_OBPzMcUnCCatN0_03mIXA';return true;">.inl</a>).</div><div><=
br></div><div>2. It's not that much boiler plate code you have to write, or=
 rather it's not much of a hassle to do it. Sure this may be the case for *=
most* classes. However, consider the case in which we wish to add or remove=
 some template parameters; we have to update a lot of sections than necessa=
ry, just to make the code build. For example: consider the previous example=
, except we turn <font face=3D"courier new, monospace">Vec2&lt;T&gt;</font>=
 into <font face=3D"courier new, monospace">Vec&lt;T, Size&gt;</font> where=
 <font face=3D"courier new, monospace">Size</font> is an integer describing=
 the dimension of the vector data structure. We</div><div>actually will sti=
ll have to update a lot of sections of our code, and that is adding , Size =
to everywhere we wrote <font face=3D"courier new, monospace">Vec&lt;T&gt;::=
 </font>(I want to discuss a solution to this in another proposal idea, as =
I mentioned above), but the amount of boiler plate has still been greatly r=
educed.</div><div><span style=3D"font-size:large"><br></span></div><div><sp=
an style=3D"font-size:large">Another Example</span><br></div><div><br></div=
><div></div></div><div style=3D"border:1px solid rgb(187,187,187);word-wrap=
:break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"co=
lor:#008">template</span><span style=3D"color:#000"> </span><span style=3D"=
color:#660">&lt;</span><span style=3D"color:#008">class</span><span style=
=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"><br></span><span style=3D"color:#008">namespace</span><span=
 style=3D"color:#000"> math_constants<br></span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"=
color:#008">namespace</span><span style=3D"color:#000"> detail<br>&nbsp; &n=
bsp; </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><=
br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color:#008">constexpr<=
/span><span style=3D"color:#000"> T compute_pi</span><span style=3D"color:#=
660">();</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span st=
yle=3D"color:#660">}</span><span style=3D"color:#000"><br><br><br>&nbsp; &n=
bsp; </span><span style=3D"color:#008">constexpr</span><span style=3D"color=
:#000"> </span><span style=3D"color:#008">const</span><span style=3D"color:=
#000"> T pi </span><span style=3D"color:#660">=3D</span><span style=3D"colo=
r:#000"> detail</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">compute_pi</span><span style=3D"color:#660">();</span><span style=
=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#800">// etc.=
</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">}</=
span><span style=3D"color:#000"><br><br></span><span style=3D"color:#800">/=
/...</span><span style=3D"color:#000"><br><br></span><span style=3D"color:#=
008">int</span><span style=3D"color:#000"> main</span><span style=3D"color:=
#660">()</span><span style=3D"color:#000"><br></span><span style=3D"color:#=
660">{</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span styl=
e=3D"color:#008">using</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">namespace</span><span style=3D"color:#000"> math_constants<=
/span><span style=3D"color:#080">&lt;double</span><font color=3D"#666600"><=
span style=3D"color:#080">&gt;</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br><br></span></font><span style=3D"color:#000">&n=
bsp; &nbsp; std</span><span style=3D"color:#660">::</span><span style=3D"co=
lor:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span style=
=3D"color:#000"> pi </span><span style=3D"color:#660">&lt;&lt;</span><span =
style=3D"color:#000"> </span><span style=3D"color:#080">'\n'</span><span st=
yle=3D"color:#660">;</span><span style=3D"color:#000"><br></span><span styl=
e=3D"color:#660">}</span></div></code></div><div><br></div><div>Note that t=
his particular example could be implemented within a struct in the current =
standard.<br></div><div><br></div><div>I would really like to hear your tho=
ughts about this idea and any constructive criticism :) Thanks.</div></div>=
</blockquote></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2424_1889504685.1417536223832--
------=_Part_2423_1910832389.1417536223832--

.