tuple vector and initializer_list

前端 未结 3 540
太阳男子
太阳男子 2021-01-03 18:31

I tried to compile the following snippets with gcc4.7

vector > vp = {{1,\'a\'},{2,\'b\'}};
//For pair vector, it works like a char         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-03 19:24

    The relevant std::tuple constructors are explicit. This means that what you want to do is not possible, since the syntax you want to use is defined in terms of copy initialization (which forbids calling an explicit constructor). In contrast, std::tuple { 1, 2.2, 'X' } uses direct initialization. std::pair does have non-explicit constructors only.

    Either use direct-initialization or one of the Standard tuple factory function (e.g. std::make_tuple).

提交回复
热议问题