|
Boost Users : |
Subject: [Boost-users] [range] Best way to construct a std::set from a range?
From: Gabriel Redner (gredner_at_[hidden])
Date: 2010-03-02 19:26:01
If I have a pair of iterators, I can construct a set like so:
std::set<SomeType> s(it1, it2);
If instead I have a range, I can adapt it like so:
std::set<SomeType> s(boost::begin(range), boost::end(range));
However, my range object is being constructed on the fly. I'd like to
be able to do:
std::set<SomeType> s(MakeRange(args));
But clearly this is not supported by the library. It seems I need to
store the range object in a variable in order to do this, which
defeats the syntax-simplifying benefits of using ranges. Can this be
avoided? Are there some recommended no-overhead tricks for doing this
that achieve a clean syntax? Implicit conversions? Explicit "ToSet"
conversion functions? Can boost.assign be of help? (My initial
reading of the assign documentation suggests not, but perhaps I'm
missing something). I'm also not averse to a macro so long as it
looks "language-like," but so far I haven't produced anything
satisfactory. Has anyone else wrestled with this one and come out
victorious?
Thanks,
-Gabe
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