test
parent
a4220e3c0d
commit
704e77419f
|
@ -54,14 +54,10 @@ namespace blt
|
|||
namespace blt
|
||||
{
|
||||
template<typename TYPE_ITR>
|
||||
class enumerate
|
||||
class enumerator
|
||||
{
|
||||
private:
|
||||
size_t index = 0;
|
||||
TYPE_ITR begin;
|
||||
TYPE_ITR end;
|
||||
public:
|
||||
class enumerate_itr
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
@ -71,10 +67,62 @@ namespace blt
|
|||
using reference = typename TYPE_ITR::reference;
|
||||
private:
|
||||
size_t index = 0;
|
||||
TYPE_ITR current;
|
||||
public:
|
||||
explicit iterator(TYPE_ITR current): current(current)
|
||||
{};
|
||||
|
||||
iterator& operator++()
|
||||
{
|
||||
index++;
|
||||
++current;
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator operator++(int)
|
||||
{
|
||||
iterator retval = *this;
|
||||
++(*this);
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool operator==(iterator other) const
|
||||
{ return current == other.current; }
|
||||
|
||||
bool operator!=(iterator other) const
|
||||
{ return !(*this == other); }
|
||||
|
||||
std::pair<size_t, const reference> operator*() const
|
||||
{
|
||||
return {index, *current};
|
||||
};
|
||||
};
|
||||
|
||||
explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(begin), end_(end)
|
||||
{}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return begin_;
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return end_;
|
||||
}
|
||||
|
||||
private:
|
||||
iterator begin_;
|
||||
iterator end_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static inline enumerator<typename T::iterator> enumerate(T container)
|
||||
{
|
||||
return enumerator{container.begin(), container.end()};
|
||||
}
|
||||
|
||||
|
||||
#if defined(__GNUC__) || defined(__llvm__)
|
||||
#define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline))
|
||||
#else
|
||||
|
|
|
@ -36,15 +36,21 @@ void printLines(const std::vector<std::string>& lines)
|
|||
std::cout << v << "\n";
|
||||
}
|
||||
|
||||
void testEnumerate(const std::vector<std::string>& test){
|
||||
|
||||
void testEnumerate(const std::vector<std::string>& test)
|
||||
{
|
||||
for (auto pair : blt::enumerate(test))
|
||||
{
|
||||
std::cout << pair.first << ": " << pair.second << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void getfucked(){
|
||||
void getfucked()
|
||||
{
|
||||
BLT_ASSERT(false);
|
||||
}
|
||||
|
||||
void fuckered(){
|
||||
void fuckered()
|
||||
{
|
||||
getfucked();
|
||||
}
|
||||
|
||||
|
@ -90,7 +96,8 @@ void blt::test::utility::run()
|
|||
// left
|
||||
(new string::BinaryTreeFormatter::Node("member"))
|
||||
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.15"))
|
||||
->with((new string::BinaryTreeFormatter::Node("total > 500"))->with(new string::BinaryTreeFormatter::Node("total -= 25"))),
|
||||
->with((new string::BinaryTreeFormatter::Node("total > 500"))
|
||||
->with(new string::BinaryTreeFormatter::Node("total -= 25"))),
|
||||
(new string::BinaryTreeFormatter::Node("total -= total * 0.05"))),
|
||||
// right
|
||||
(new string::BinaryTreeFormatter::Node("quality"))
|
||||
|
|
Loading…
Reference in New Issue