Topic: Idea and solution: Better STD functions and if clause


Author: Viktor Attila Jenei <jenei.viktor@gmail.com>
Date: Tue, 25 Apr 2017 11:13:51 -0700 (PDT)
Raw View
------=_Part_272_1834101693.1493144031405
Content-Type: multipart/alternative;
 boundary="----=_Part_273_1078324013.1493144031405"

------=_Part_273_1078324013.1493144031405
Content-Type: text/plain; charset=UTF-8

Hello!

  There is a way to be a contributor to the C++ standards? I have some
ideas, that i want to make.

*1.*
  I think, it could be much better, if the can use std functions only with
containers and not with begin and end iterators.
  Example the solution:
namespace std
{
    template< typename T >
    using Iterator = typename T::iterator;

    template< typename Cont, typename Pred >
    inline Iterator< Cont > find_if( Cont& c, Pred p )
    {


    template< typename Cont, typename Pred >
    inline void for_each( Cont& c, Pred p )
    {
        std::for_each( begin( c ), end( c ), p );
    }

    template< typename Cont >
    inline Iterator< Cont > copy( Cont& in, Cont& out )
    {
        return std::copy( begin( in ), end( in ), begin( out ) );
    }

    template< typename Cont, typename Pred >
    inline Iterator< Cont > copy_if( Cont& in, Cont& out, Pred p )
    {
        return std::copy_if( begin( in ), end( in ), begin( out ), p );
    }
}

  So the programmers can use these functions (and the others too), like:
   // v is a vector of int
*   for_each( v, []( int& e ) { cout << e << " "; } );*
*   sort( indices, [&v2]( int a, int b ) { return v2[ a ] < v2[ b ]; } );*
*   if (is_sorted( v )) { .... }*

  I think this will be cool, and nice, not?

*2.*
New if clause (with variable declaration):

*    string result="a.b.c.d";*
*    if ( ( auto f1 = result.rfind('.') ) != std::string::npos)
result.replace(f1,1,"::");*
*    if ( ( auto f1 = result.rfind('.') ) != std::string::npos)
result.replace(f1,1,":");*

    These lines could be eq with these code:
    string result="a.b.c.d";
    {
      auto f1 = result.rfind('.');
      if ( f1 != std::string::npos) result.replace(f1,1,"::");
    }
    {
      auto f1 = result.rfind('.');
      if ( f1 != std::string::npos) result.replace(f1,1,":");
    }

What do you think? I can implement all of these, if you want. So, I can
improve the standards to make a better C++ language. :)

Best regards
Viktor Jenei

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/4d628cb7-c5ac-4d17-ad2e-5d04b9cc9c37%40isocpp.org.

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

<div dir=3D"ltr">Hello!<div><br></div><div>=C2=A0 There is a way to be a co=
ntributor to the C++ standards? I have some ideas, that i want to make.</di=
v><div><br></div><div><b>1.</b></div><div>=C2=A0 I think, it could be much =
better, if the can use std functions only with containers and not with begi=
n and end iterators.</div><div>=C2=A0 Example the solution:</div><div><div>=
namespace std</div><div>{</div></div><div><div>=C2=A0 =C2=A0 template&lt; t=
ypename T &gt;</div><div>=C2=A0 =C2=A0 using Iterator =3D typename T::itera=
tor;</div><div><br></div><div>=C2=A0 =C2=A0 template&lt; typename Cont, typ=
ename Pred &gt;</div><div>=C2=A0 =C2=A0 inline Iterator&lt; Cont &gt; find_=
if( Cont&amp; c, Pred p )</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0=C2=A0</div><div><br></div><div>=C2=A0 =C2=A0 template&lt; ty=
pename Cont, typename Pred &gt;</div><div>=C2=A0 =C2=A0 inline void for_eac=
h( Cont&amp; c, Pred p )</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 std::for_each( begin( c ), end( c ), p );</div><div>=C2=A0 =
=C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 template&lt; typename Cont =
&gt;</div><div>=C2=A0 =C2=A0 inline Iterator&lt; Cont &gt; copy( Cont&amp; =
in, Cont&amp; out )</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 return std::copy( begin( in ), end( in ), begin( out ) );</div><=
div>=C2=A0 =C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 template&lt; typ=
ename Cont, typename Pred &gt;</div><div>=C2=A0 =C2=A0 inline Iterator&lt; =
Cont &gt; copy_if( Cont&amp; in, Cont&amp; out, Pred p )</div><div>=C2=A0 =
=C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return std::copy_if( begin( =
in ), end( in ), begin( out ), p );</div><div>=C2=A0 =C2=A0 }</div></div><d=
iv>}</div><div><br></div><div>=C2=A0 So the programmers can use these funct=
ions (and the others too), like:=C2=A0</div><div>=C2=A0 =C2=A0// v is a vec=
tor of int</div><div><b>=C2=A0 =C2=A0for_each( v, []( int&amp; e ) { cout &=
lt;&lt; e &lt;&lt; &quot; &quot;; } );</b></div><div><b>=C2=A0 =C2=A0sort( =
indices, [&amp;v2]( int a, int b ) { return v2[ a ] &lt; v2[ b ]; } );</b><=
/div><div><b>=C2=A0 =C2=A0if (is_sorted( v )) { .... }</b></div><div><br></=
div><div>=C2=A0 I think this will be cool, and nice, not?</div><div><br></d=
iv><div><b>2.</b>=C2=A0</div><div>New if clause (with variable declaration)=
:</div><div><br></div><div><div><b>=C2=A0 =C2=A0 string result=3D&quot;a.b.=
c.d&quot;;</b></div><div><b>=C2=A0 =C2=A0 if ( ( auto f1 =3D result.rfind(&=
#39;.&#39;) ) !=3D std::string::npos) result.replace(f1,1,&quot;::&quot;);<=
/b></div><div><b>=C2=A0 =C2=A0 if ( ( auto f1 =3D result.rfind(&#39;.&#39;)=
 ) !=3D std::string::npos) result.replace(f1,1,&quot;:&quot;);</b></div></d=
iv><div><br></div><div>=C2=A0 =C2=A0 These lines could be eq with these cod=
e:</div><div><div>=C2=A0 =C2=A0 string result=3D&quot;a.b.c.d&quot;;</div><=
div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 auto f1 =3D result.rfind=
(&#39;.&#39;);</div><div>=C2=A0 =C2=A0 =C2=A0 if ( f1 !=3D std::string::npo=
s) result.replace(f1,1,&quot;::&quot;);</div><div>=C2=A0 =C2=A0 }</div><div=
>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 auto f1 =3D result.rfind(&#=
39;.&#39;);</div><div>=C2=A0 =C2=A0 =C2=A0 if ( f1 !=3D std::string::npos) =
result.replace(f1,1,&quot;:&quot;);</div><div>=C2=A0 =C2=A0 }</div></div><d=
iv><br></div><div>What do you think? I can implement all of these, if you w=
ant. So, I can improve the standards to make a better C++ language. :)</div=
><div><br></div><div>Best regards</div><div>Viktor Jenei</div><div><br></di=
v></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4d628cb7-c5ac-4d17-ad2e-5d04b9cc9c37%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4d628cb7-c5ac-4d17-ad2e-5d04b9cc9c37=
%40isocpp.org</a>.<br />

------=_Part_273_1078324013.1493144031405--

------=_Part_272_1834101693.1493144031405--

.


Author: Jens Maurer <Jens.Maurer@gmx.net>
Date: Tue, 25 Apr 2017 20:17:23 +0200
Raw View
On 2017-04-25 20:13, Viktor Attila Jenei wrote:
> Hello!
>
>   There is a way to be a contributor to the C++ standards? I have some
> ideas, that i want to make.
>
> *1.*
>   I think, it could be much better, if the can use std functions only
> with containers and not with begin and end iterators.

Have you read the "Ranges TS"?  I haven't, but I guess it's going
where you want to be.

> *2.*
> New if clause (with variable declaration):

Available in C++17; see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r1.html

Jens

--
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/e8eafb5c-5e87-a339-dd9f-05186bd7084f%40gmx.net.

.