Suppose I have a non-copyable and non-moveable class Person:
struct Person
{
int m_icNum;
explicit Person(int icNum) : m_icNum(icNum) {}
Person (const Person & other) = delete;
Person (Person && other) = delete;
};
And another class PersonContainer:
struct PersonContainer
{
boost::optional<Person> m_person;
explicit PersonContainer(int icNum)
: m_person( icNum >= 0 ? Person(icNum) : boost::none) // this does not compile because the two operands of ternary operator ? must have the same type
{}
};
Apparently I cannot construct m_person using ternary expression in the initializer list. An alternative is to construct it in the ctor body using boost::in_pace, but I wonder if there is a nice way to construct it in the initializer list.