Re: Is using a braced-list as a function parameter only for std: : initializer_list?
On 2013-09-30 09:15, Daryle Walker wrote:
On Sunday, September 29, 2013 10:00:05 PM UTC-4, Daryle Walker wrote:
Code like:
template < unsigned N >
class MyClass
{
public:
//...
template < typename ...Args > bool MyFunc( Args &&...args );
bool MyFunc( std::array<unsigned, N> &a );
//...
};
I can make calls like "MyFunc(a, b, c)" just fine. But when I
try "MyFunc({d, e, f})" to trigger the std::array overload, I get
complaints on no candidate being found; that initializer-list (the
internal compiler concept, not necessarily std::initializer_list)
couldn't convert to anything appropriate.
I know that you can use a std::initializer_list as a function
parameter and it'll work, but can you use any type that can use a
braced-list (assuming the right parameter type)?
Found the answer while wandering around StackOverflow.
The class definition is fine.
No, it is not (see my other reply).
But when calling the code, I have to use
std::array's proper double braces to work. I guess sloppy brace placement
won't work; any such foolishness will match std::initializer_list first.
I don't see any std::initializer_list in your example code. The
additional problem that you were stumbling across was due to
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1270
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]