optional<char> get_async_input()
{
if ( !queue.empty() )
return optional<char>(queue.top());
else return optional<char>();
}
void receive_async_message()
{
optional<char> rcv ;
while ( (rcv = get_async_input()) && !timeout() )
output(*rcv);
}
optional<string> name ;
if ( database.open() )
{
name = database.lookup(employer_name) ;
}
else
{
if ( can_ask_user )
name = user.ask(employer_name) ;
}
if ( name )
print(*name);
else print("employer's name not found!");
class figure
{
public:
figure()
{
}
void clip_in_rect ( rect const& rect )
{
....
m_clipping_rect = rect ;
}
void draw ( canvas& cvs )
{
if ( m_clipping_rect )
do_clipping(*m_clipping_rect);
cvs.drawXXX(..);
}
rect const* get_clipping_rect() { return get_pointer(m_clipping_rect); }
private :
optional<rect> m_clipping_rect ;
};
class ExpensiveCtor { ... } ;
class Fred
{
Fred() : mLargeVector(10000) {}
std::vector< optional<ExpensiveCtor> > mLargeVector ;
} ;