Hi. Calling boost::gregorian::from_string with string value = 2003-07-28 produces a range exception, i.e. year supposedly does not fall inside the range covered by boost::gregorian::date!!!! Any suggestions? Greetings, Andre.
On Tue, 09 Sep 2003 11:04:32 +0200, Andre du Toit wrote
Hi.
Calling boost::gregorian::from_string with string value = 2003-07-28 produces a range exception, i.e. year supposedly does not fall inside the range covered by boost::gregorian::date!!!!
Any suggestions?
Which boost? What platform? Exact code? using namespace boost::gregorian; std::string s1("2003-07-28"); date d1(from_string(s1)); This works fine for me on gcc 3.2, linux. Jeff
Boost gurus, I am using boost::bind in combination with boost::signals for a GUI toolkit. The signals return bool for convenience, but it is often desireable to bind a void function and connect it to a signal. Is there a convenient way to assign a return value for a void function. As an example: ----------------------------------------------------------------- struct panel { void print() { std::cout << "print" << std::endl; } } struct widget { boost::signal<bool ()> on_event; } panel p; widget w; // is there some way to do something like this? w.on_event.connect(boost::bind_return(panel::print, &p, true)); ----------------------------------------------------------------- Many thanks in advance, Darren Hart
Darren Vincent Hart wrote:
Boost gurus,
I am using boost::bind in combination with boost::signals for a GUI toolkit. The signals return bool for convenience, but it is often desireable to bind a void function and connect it to a signal. Is there a convenient way to assign a return value for a void function.
As an example:
-----------------------------------------------------------------
struct panel { void print() { std::cout << "print" << std::endl; } }
struct widget { boost::signal<bool ()> on_event; }
panel p; widget w;
// is there some way to do something like this? w.on_event.connect(boost::bind_return(panel::print, &p, true));
You can do this with Lambda: using namespace boost::lambda; w.on_event.connect( (bind(panel::print, &p), true) ); but not with boost::bind, sorry. Not out of the box, anyway. template<class F, class V> class override_return_t { private: F f_; V v_; public: typedef V result_type; override_return_t(F const & f, V const & v): f_(f), v_(v) { } result_type operator()() { f_(); return v_; } result_type operator()() const { f_(); return v_; } }; template<class F, class V> override_return_t<F, V> override_return(F const & f, V const & v) { return override_return_t<F, V>(f, v); } #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> void g() { std::cout << "g()\n"; } int main() { boost::function<bool()> f = override_return(boost::bind(g), true); std::cout << f() << std::endl; } You can even go a bit further and bring boost::bind one step closer to its lambda counterpart: template<class R, class F, class L, class V> override_return_t<boost::_bi::bind_t<R, F, L>, V> operator,(boost::_bi::bind_t<R, F, L> const & f, V const & v) { return override_return_t<boost::_bi::bind_t<R, F, L>, V>(f, v); } int main() { boost::function<bool()> f = (boost::bind(g), true); std::cout << f() << std::endl; }
participants (4)
-
Andre du Toit
-
Darren Vincent Hart
-
Jeff Garland
-
Peter Dimov