mardi 27 novembre 2018

Use initialization list with boost-parameter

The following code will not compile because in the last call to 'demo' the compiler cannot deduce a type from the initialization-list.

#include <boost/parameter/name.hpp>
#include <boost/parameter/preprocessor.hpp>
#include <iostream>
#include <array>

BOOST_PARAMETER_NAME(arg)

BOOST_PARAMETER_FUNCTION(
    (void),
    demo,
    tag,
    (optional
    (arg, (std::array<int, 3>), (std::array<int,3>{}))
    )
    )
{
    std::cout << arg[1] << std::endl;
}


int main()
{   
    demo();
    demo(_arg=std::array<int,3>({1,2,3}));
    // 28:14: error: no match for 'operator=' 
    // (operand types are 'const boost::parameter::keyword<tag::arg>' 
    // and '<brace-enclosed initializer list>')
    demo(_arg={1,2,3});
}

Is there a way to combine initialization-lists with boost-parameter without adding an explicit call to the constructor of array?

Aucun commentaire:

Enregistrer un commentaire