Reputation: 73366
From my previous question about std::pair, I thought I would be able to do something like the following, but it won't compile.
typedef Point::FT float;
std::vector<std::tuple<Point::FT, int, int> > branch{ (int)(max_leaf_check * mul_factor),
{ std::numeric_limits<Point::FT>::max(), -1 , -1} };
Error:
error: converting to ‘const value_type {aka const std::tuple<float, int, int>}’ from initializer list would use explicit constructor ‘std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {float, int, int}, <template-parameter-2-2> = void, _Elements = {float, int, int}]’
How do I fix it? If it can't be fixed, is there any other way to do the initialization in one line?
As a follow up, I can't even make it work with push_back()
.
Point::FT new_dist;
size_t other_child_i, tree_i;
branch.push_back({new_dist, other_child_i, tree_i});
Similar error.
Upvotes: 2
Views: 300
Reputation: 254431
How do I fix it?
You can't; the explicit constructor prevents implicit brace-initialisation.
If it can't be fixed, is there any other way to do the initialization in one line?
std::make_tuple(std::numeric_limits<Point::FT>::max(), -1 , -1)
As a follow up, I can't even make it work with
push_back()
.
branch.emplace_back(new_dist, other_child_i, tree_i);
Upvotes: 4