I'm having trouble with boost::variant
(using boost 1.67.0).
When my template parameter list includes both bool
and std::string
, any variant objects which should be treated as string, seem to be implicitly bound to bool instead. For example:
using Varval = boost::variant<bool, std::string>;
void main()
{
std::vector<Varval> vect{ true, false, "Hello_World" };
std::cout << "[ ";
for (const auto &v : vect)
std::cout << v << " ";
std::cout << "]\n";
}
Outputs:
[ 1 0 1 ]
whereas if I change nothing but the first template argument, from bool
to int
, it works fine:
using Varval = boost::variant<int, std::string>;
void main()
{
std::vector<Varval> vect{ true, false, "Hello_World" };
std::cout << "[ ";
for (const auto &v : vect)
std::cout << v << " ";
std::cout << "]\n";
}
Properly outputs:
[ 1 0 Hello_World ]
Any ideas?