简体   繁体   English

初始化std :: pair <double,std :: array <std :: pair <double,double>,3 >>

[英]Initialising std::pair<double, std::array<std::pair<double, double>, 3> >

Can anyone advise on the correct syntax for the std::make_pair call in the std::vector::push_back call in the code below: 任何人都可以在下面的代码中为std :: vector :: push_back调用中的std :: make_pair调用提供正确的语法建议:

#include <array>
#include <vector>
#include <utility>

int main()
{
    typedef std::pair<double, double> PairType;
    std::vector<std::pair<double, std::array<PairType, 3> > > myVector;

    double Key = 0.0;
    PairType Pair1 = std::make_pair(1.0, 2.0);
    PairType Pair2 = std::make_pair(3.0, 4.0);
    PairType Pair3 = std::make_pair(5.0, 6.0);

    myVector.push_back(std::make_pair(Key, { Pair1, Pair2, Pair3 } )); // Syntax Error

    return 0;
}

The compiler (MS VS2015.2) cannot determine the type of the second argument in the std::make_pair call, which is understandable yet I don't know how to enlighten it. 编译器(MS VS2015.2)无法确定std :: make_pair调用中第二个参数的类型,这是可以理解的,但我不知道如何启发它。

It looks like the compiler cannot figure out that { Pair1, Pair2, Pair3 } is an std::array of three pairs. 看起来编译器无法弄清楚{ Pair1, Pair2, Pair3 }是三对的std::array Specifying the type explicitly should work: 明确指定类型应该有效:

myVector.push_back(std::make_pair(Key, std::array<PairType,3>{ Pair1, Pair2, Pair3 } ));

Demo. 演示。

You could use std::experimental::make_array , if the compiler supports Library fundamentals v2 : 如果编译器支持库基础知识v2 ,您可以使用std :: experimental :: make_array

using std::experimental::make_array;
myVector.push_back(std::make_pair(Key, make_array(Pair1, Pair2, Pair3) ));

LIVE from GCC 来自GCC的现场直播

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM