test
parent
a4220e3c0d
commit
704e77419f
|
@ -54,14 +54,10 @@ namespace blt
|
||||||
namespace blt
|
namespace blt
|
||||||
{
|
{
|
||||||
template<typename TYPE_ITR>
|
template<typename TYPE_ITR>
|
||||||
class enumerate
|
class enumerator
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
size_t index = 0;
|
|
||||||
TYPE_ITR begin;
|
|
||||||
TYPE_ITR end;
|
|
||||||
public:
|
public:
|
||||||
class enumerate_itr
|
class iterator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using iterator_category = std::input_iterator_tag;
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
@ -71,9 +67,61 @@ namespace blt
|
||||||
using reference = typename TYPE_ITR::reference;
|
using reference = typename TYPE_ITR::reference;
|
||||||
private:
|
private:
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
TYPE_ITR current;
|
||||||
public:
|
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__)
|
#if defined(__GNUC__) || defined(__llvm__)
|
||||||
#define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline))
|
#define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline))
|
||||||
|
|
|
@ -36,15 +36,21 @@ void printLines(const std::vector<std::string>& lines)
|
||||||
std::cout << v << "\n";
|
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);
|
BLT_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fuckered(){
|
void fuckered()
|
||||||
|
{
|
||||||
getfucked();
|
getfucked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,14 +95,15 @@ void blt::test::utility::run()
|
||||||
assign1.getRoot()->with(
|
assign1.getRoot()->with(
|
||||||
// left
|
// left
|
||||||
(new string::BinaryTreeFormatter::Node("member"))
|
(new string::BinaryTreeFormatter::Node("member"))
|
||||||
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.15"))
|
->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"))
|
||||||
(new string::BinaryTreeFormatter::Node("total -= total * 0.05"))),
|
->with(new string::BinaryTreeFormatter::Node("total -= 25"))),
|
||||||
|
(new string::BinaryTreeFormatter::Node("total -= total * 0.05"))),
|
||||||
// right
|
// right
|
||||||
(new string::BinaryTreeFormatter::Node("quality"))
|
(new string::BinaryTreeFormatter::Node("quality"))
|
||||||
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.02")),
|
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.02")),
|
||||||
(new string::BinaryTreeFormatter::Node("total -= total * 0.05")))
|
(new string::BinaryTreeFormatter::Node("total -= total * 0.05")))
|
||||||
);
|
);
|
||||||
printLines(assign1.construct());
|
printLines(assign1.construct());
|
||||||
|
|
||||||
blt::string::TableFormatter tableQ2i1("Iteration 0");
|
blt::string::TableFormatter tableQ2i1("Iteration 0");
|
||||||
|
|
Loading…
Reference in New Issue