Generalize boost::optional as boost::range to support boost::range::adaptors

3 Jun
2010
3 Jun
'10
12:52 p.m.
Hi all, I've implemented a small adaptor to make boost::optional behave like a range. This extends the functionality of boost::optional to be more like the scala Option class and the haskell Maybe monad. A trivial motivating example is int plus(const int & i){ return i + 1; } void foo(boost::optional<int> opt_v){ boost::copy ( opt_v | boost::adaptors::transformed(plus) , std::ostream_iterator<int>(std::cout) ); } foo(10) outputs 11 The full implementation and details are at http://xtargets.heroku.com/2010/06/03/using-boostoptional-as-a-range/ Does anybody think this is a useful extension to boost::optional or would be willing to provide feedback or suggestions on the implementation. Regards Brad
5395
Age (days ago)
5395
Last active (days ago)
0 comments
1 participants
participants (1)
-
bradphelanï¼ xtargets.com