The following code does not compile:
#include <boost/mpl/list_c.hpp>
enum class DataType : int {
t1 = 0,
t2 = 1,
t3 = 2
};
int main()
{
boost::mpl::list_c<DataType, DataType::t1, DataType::t2> lc2;
}
I have to cast my values, like this (which compiles):
#include <boost/mpl/list_c.hpp>
enum class DataType : int {
t1 = 0,
t2 = 1,
t3 = 2
};
int main()
{
boost::mpl::list_c<int, static_cast<int>(DataType::t1), static_cast<int>(DataType::t2)> lc2;
}
I can also create the list from a variadic list of types, like this (also compiles):
#include <boost/mpl/list_c.hpp>
template<int... ints>
void create_list() {
boost::mpl::list_c<int, ints...> lc;
}
int main()
{
create_list<1,2,3>();
}
However, how do I create the list from a variadic list of types like below (doesn't compile):
#include <boost/mpl/list_c.hpp>
enum class DataType : unsigned char {
t1 = 0,
t2 = 1,
t3 = 2
};
template<DataType... datatypes>
void create_list() {
boost::mpl::list_c<DataType, datatypes...> lc;
}
int main()
{
create_list<DataType::t1, DataType::t2>();
}
This gives the following compiler error:
In instantiation of 'void create_list() [with DataType ...datatypes = {(DataType)0u, (DataType)1u}]':
13:43: required from here
9:46: error: could not convert template argument '(DataType)0u' to 'long int'
9:46: error: could not convert template argument '(DataType)1u' to 'long int'
I also cannot cast when calling the create_list function, like this:
create_list<static_cast<unsigned char>(DataType::t1), static_cast<unsigned char>(DataType::t2)>();
since, my variadic type list has been passed by my client.