Brett 2023-12-08 20:44:45 -05:00
parent a4220e3c0d
commit 704e77419f
2 changed files with 71 additions and 16 deletions

View File

@ -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

View File

@ -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();
}
@ -89,14 +95,15 @@ void blt::test::utility::run()
assign1.getRoot()->with(
// 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"))),
(new string::BinaryTreeFormatter::Node("total -= total * 0.05"))),
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.15"))
->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"))
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.02")),
(new string::BinaryTreeFormatter::Node("total -= total * 0.05")))
);
->with((new string::BinaryTreeFormatter::Node("total -= total * 0.02")),
(new string::BinaryTreeFormatter::Node("total -= total * 0.05")))
);
printLines(assign1.construct());
blt::string::TableFormatter tableQ2i1("Iteration 0");