How to initialize C++17 vector of pairs with optional element

Eugene :

In C++17, how do you declare and initialize a vector of pairs(or tuples) with an optional element?

    std::vector<std::pair<int, optional<bool> > > vec1 = { {1, true},
                                                           {2, false}, 
                                                           {3, nullptr}};

I have a pair where the second element may be null/optional.

bitmask :

You are looking for std::nullopt instead of nullptr.

std::vector<std::pair<int, std::optional<bool> > > vec1 =
  { {1, true}, {2,false}, {3,std::nullopt} };

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=301527&siteId=1