|
Boost Users : |
Subject: [Boost-users] Generalize boost::optional as boost::range to support boost::range::adaptors
From: bradphelan_at_[hidden]
Date: 2010-06-03 08:52:29
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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net