This is a general approach, if it is likely that a method cannot return an object, make the method return bool:
bool get_value(Type& type) { if ( /*check variant emptyness*/) // one can use this - http://stackoverflow.com/a/7668530/670719 return false; // else assign type }
Comments on your decisions:
a) if you return Empty, you still have to do a check after calling the method. So why add more types if you already have a built-in bool.
b) Type () may have the same meaning as the legal variable
c) The exception is something exceptional, but from your description "often"
d) your problem is that you cannot use Type and at the same time you cannot return boost :: variant, so adding another type with additional problems with the owners raises more questions about what happens without solving the initial problem clean interface.
source share