TreeExplorer: add shortcut to adapt STL container automatically

...selecting the iterator or const iterator as apropriate
This commit is contained in:
Fischlurch 2017-11-19 17:35:00 +01:00
parent fd3d6fb60e
commit cbb35d7161
2 changed files with 41 additions and 7 deletions

View file

@ -147,16 +147,42 @@ namespace lib {
/////TODO RLY?
using util::unConst;
using lib::meta::enable_if;
using lib::meta::disable_if;
using std::function;
using meta::_Fun;
// using util::unConst;
// using lib::meta::enable_if;
// using lib::meta::disable_if;
// using std::function;
// using meta::_Fun;
template<class CON>
using iterator = typename meta::Strip<CON>::TypeReferred::iterator;
template<class CON>
using const_iterator = typename meta::Strip<CON>::TypeReferred::const_iterator;
template<class CON>
struct StlRange
: RangeIter<iterator<CON>>
{
StlRange() =default;
StlRange (CON& container)
: RangeIter<iterator<CON>> {begin(container), end(container)}
{ }
// standard copy operations acceptable
};
template<class CON>
struct StlRange<const CON>
: RangeIter<const_iterator<CON>>
{
StlRange() =default;
StlRange (CON const& container)
: RangeIter<const_iterator<CON>> {begin(container), end(container)}
{ }
// standard copy operations acceptable
};
}//(End) namespace iter_explorer : predefined policies and configurations
namespace {
namespace { // TreeExplorer traits
using meta::enable_if;
using meta::Yes_t;
@ -209,7 +235,9 @@ namespace lib {
template<class SRC>
struct _TreeExplorerTraits<SRC, enable_if<shall_wrap_STL_Iter<SRC>>>
{
static_assert (!sizeof(SRC), "PLING: STL Iter");
static_assert (not std::is_rvalue_reference<SRC>::value,
"container needs to exist elsewhere during the lifetime of the iteration");
using SrcIter = iter_explorer::StlRange<SRC>;
};
}//(End) TreeExplorer traits

View file

@ -292,6 +292,12 @@ namespace test{
CHECK (materialise(ii) == "-2-3--5-8--13");
CHECK (materialise(jj) == "3--5-8--13");
// can adapt STL container automatically
auto kk = treeExplore(numz);
CHECK (!isnil (kk));
CHECK (1 == *kk);
CHECK (materialise(kk) == "1--2-3--5-8--13");
}