|
Boost Users : |
Subject: Re: [Boost-users] [review][assign] Formal review of Assign v2 ongoing
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2011-06-21 18:05:55
er wrote:
> You say "I ordinarily only initialize containers to literals when
> writing unit tests.". In this case, I think you are right that you
> can't beat C++0x initializer lists. But, you still may need to fill a
> container, as above. And also, consider the cases below:
>
> #include <vector>
> #include <queue>
> #include <string>
> #include <tuple>
> #include <boost/assign/v2/include/csv_deque_ext.hpp>
>
> int main()
> {
> typedef std::string s_;
> {
> typedef std::tuple<s_, int> t_;
> typedef std::vector<t_> v_;
> v_ v1 = {
> t_( "a", 1 ),
> t_( "b", 2 ),
> t_( "c", 3 ),
> t_( "d", 4 ),
> t_( "e", 5 )
> };
> using namespace boost::assign::v2;
> v_ v2 = converter(
> csv_deque<t_, 2>( "a", 1, "b", 2, "c", 3, "d", 4, "e", 5)
> );
> }
No, initializer lists can apply to the elements and be nested.
v_ v1 = {
{ "a", 1 },
{ "b", 2 },
{ "c", 3 },
{ "d", 4 },
{ "e", 5 }
};
Arguably the extra {} around each vector element in the new initializer syntax is more readable than the proposed assign v2 syntax. Tuple and deque support initializer list as do all classes with constructors and structs.
I would like to know if there will be a boost.parameter v2 that works with initializer lists and default values of struct members.
struct S {
int a;
int b = 1;
int c = 2;
}
S s1 = {0, 1, 2};
S s2 = {0}; //use default b and c
S s3 = {0, 1}; //use default c
S s4 = {0, c = 2}; //use default b
That would be very nice, but I don't know if we can accomplish it.
Regards,
Luke
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net