You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we have 3 ways to initialize a box with value T{...} but no way to initialize one with value T(...). These causes problems for types with a constructor that takes a std::initializer_list. For example, the following prints out 2502:
struct test
{
test(int a) : a(a) {}
test(const test& that) : a(that.a) {}
test(test &&that) : a(that.a) {}
template<class T>
test(const std::initializer_list<T> &l) {
a = 50;
}
int a;
};
int main()
{
test t1(2);
immer::box<test> t2(t1);
test t3(t1);
std::cout << t1.a << std::endl << t2.get().a << std::endl << t3.a << std::endl;
}
A real-life example would be https://github.com/nlohmann/json, for which the list initialization wraps whatever passed to it into a JSON array.
I think we need to have some strategy to differentiate between these two.
The text was updated successfully, but these errors were encountered:
tusooa
changed the title
Can't really construct a box with a known value of value type
Can't really construct a box with non-list initialization
Aug 19, 2020
Ohhh, damn initializer lists. What compilation error are you getting? That case is intended to work. I think I can figure a way to fix that particular case by specifically distinguishing copy/move constructing the underlying T.
Ohhh, damn initializer lists. What compilation error are you getting? That case is intended to work. I think I can figure a way to fix that particular case by specifically distinguishing copy/move constructing the underlying T.
Not a compilation error, but I have no way to invoke the other constructors than the one taking an initializer_list.
Currently we have 3 ways to initialize a
box
with valueT{...}
but no way to initialize one with valueT(...)
. These causes problems for types with a constructor that takes astd::initializer_list
. For example, the following prints out2
50
2
:A real-life example would be https://github.com/nlohmann/json, for which the list initialization wraps whatever passed to it into a JSON array.
I think we need to have some strategy to differentiate between these two.
The text was updated successfully, but these errors were encountered: