From bba20cf89c94e0b1758cd5d82636255402305a97 Mon Sep 17 00:00:00 2001 From: Mislav Bradac Date: Thu, 13 Apr 2017 16:17:06 +0200 Subject: [PATCH] Remove unneccessary files from utils Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D276 --- src/communication/bolt/v1/codes.hpp | 1 - .../bolt/v1/encoder/base_encoder.hpp | 5 +- src/database/graph_db.hpp | 1 - src/io/network/addrinfo.cpp | 1 - src/query/typed_value.hpp | 1 - src/storage/edge_accessor.hpp | 1 - src/storage/property_value.hpp | 1 - src/storage/record_accessor.cpp | 4 +- src/storage/record_accessor.hpp | 3 +- src/threading/sync/futex.hpp | 16 +- src/threading/thread.hpp | 2 - src/utils/align.hpp | 9 - src/utils/bash_colors.hpp | 9 - src/utils/buffer.hpp | 34 ---- src/utils/char_str.hpp | 22 -- src/utils/eq_wrapper.hpp | 17 -- src/utils/fswatcher.hpp | 23 ++- src/utils/handle_write.hpp | 15 -- src/utils/iterator/accessor.hpp | 32 --- src/utils/iterator/combined.hpp | 55 ----- src/utils/iterator/composable.hpp | 190 ------------------ src/utils/iterator/count.hpp | 34 ---- src/utils/iterator/filter.hpp | 50 ----- src/utils/iterator/flat_map.hpp | 75 ------- src/utils/iterator/for_all.hpp | 36 ---- src/utils/iterator/inspect.hpp | 54 ----- src/utils/iterator/iterator.hpp | 16 -- src/utils/iterator/iterator_accessor.hpp | 72 ------- src/utils/iterator/iterator_base.hpp | 16 -- src/utils/iterator/lambda_iterator.hpp | 48 ----- src/utils/iterator/limited_map.hpp | 52 ----- src/utils/iterator/map.hpp | 49 ----- src/utils/iterator/query.hpp | 23 --- src/utils/iterator/range_iterator.hpp | 63 ------ src/utils/iterator/virtual_iter.hpp | 42 ---- src/utils/linux.hpp | 48 ----- src/utils/mark_ref.hpp | 25 --- src/utils/order.hpp | 8 - src/utils/pass_key.hpp | 21 -- src/utils/reference_wrapper.hpp | 39 ---- src/utils/stream_wrapper.hpp | 21 -- src/utils/string_buffer.hpp | 42 ---- src/utils/sys.hpp | 52 ----- src/utils/total_ordering.hpp | 43 +++- src/utils/total_ordering_with.hpp | 36 ---- src/utils/void.hpp | 13 -- 46 files changed, 77 insertions(+), 1343 deletions(-) delete mode 100644 src/utils/align.hpp delete mode 100644 src/utils/bash_colors.hpp delete mode 100644 src/utils/buffer.hpp delete mode 100644 src/utils/char_str.hpp delete mode 100644 src/utils/eq_wrapper.hpp delete mode 100644 src/utils/handle_write.hpp delete mode 100644 src/utils/iterator/accessor.hpp delete mode 100644 src/utils/iterator/combined.hpp delete mode 100644 src/utils/iterator/composable.hpp delete mode 100644 src/utils/iterator/count.hpp delete mode 100644 src/utils/iterator/filter.hpp delete mode 100644 src/utils/iterator/flat_map.hpp delete mode 100644 src/utils/iterator/for_all.hpp delete mode 100644 src/utils/iterator/inspect.hpp delete mode 100644 src/utils/iterator/iterator.hpp delete mode 100644 src/utils/iterator/iterator_accessor.hpp delete mode 100644 src/utils/iterator/iterator_base.hpp delete mode 100644 src/utils/iterator/lambda_iterator.hpp delete mode 100644 src/utils/iterator/limited_map.hpp delete mode 100644 src/utils/iterator/map.hpp delete mode 100644 src/utils/iterator/query.hpp delete mode 100644 src/utils/iterator/range_iterator.hpp delete mode 100644 src/utils/iterator/virtual_iter.hpp delete mode 100644 src/utils/linux.hpp delete mode 100644 src/utils/mark_ref.hpp delete mode 100644 src/utils/order.hpp delete mode 100644 src/utils/pass_key.hpp delete mode 100644 src/utils/reference_wrapper.hpp delete mode 100644 src/utils/stream_wrapper.hpp delete mode 100644 src/utils/string_buffer.hpp delete mode 100644 src/utils/sys.hpp delete mode 100644 src/utils/total_ordering_with.hpp delete mode 100644 src/utils/void.hpp diff --git a/src/communication/bolt/v1/codes.hpp b/src/communication/bolt/v1/codes.hpp index bd1fa88d3..6fdae975c 100644 --- a/src/communication/bolt/v1/codes.hpp +++ b/src/communication/bolt/v1/codes.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include "utils/underlying_cast.hpp" namespace communication::bolt { diff --git a/src/communication/bolt/v1/encoder/base_encoder.hpp b/src/communication/bolt/v1/encoder/base_encoder.hpp index 54ab18bdd..824e6ff53 100644 --- a/src/communication/bolt/v1/encoder/base_encoder.hpp +++ b/src/communication/bolt/v1/encoder/base_encoder.hpp @@ -6,6 +6,7 @@ #include "logging/logger.hpp" #include "query/typed_value.hpp" #include "utils/bswap.hpp" +#include "utils/underlying_cast.hpp" #include @@ -56,9 +57,7 @@ class BaseEncoder : public Loggable { WriteRAW(reinterpret_cast(&value), sizeof(value)); } - void WriteNull() { - WriteRAW(underlying_cast(Marker::Null)); - } + void WriteNull() { WriteRAW(underlying_cast(Marker::Null)); } void WriteBool(const bool &value) { if (value) diff --git a/src/database/graph_db.hpp b/src/database/graph_db.hpp index eb40bfe79..122d84c90 100644 --- a/src/database/graph_db.hpp +++ b/src/database/graph_db.hpp @@ -12,7 +12,6 @@ #include "storage/unique_object_store.hpp" #include "storage/vertex.hpp" #include "transactions/engine.hpp" -#include "utils/pass_key.hpp" #include "utils/scheduler.hpp" // TODO: Maybe split this in another layer between Db and Dbms. Where the new diff --git a/src/io/network/addrinfo.cpp b/src/io/network/addrinfo.cpp index c30f4d2ba..28a954324 100644 --- a/src/io/network/addrinfo.cpp +++ b/src/io/network/addrinfo.cpp @@ -4,7 +4,6 @@ #include "io/network/addrinfo.hpp" #include "io/network/network_error.hpp" -#include "utils/underlying_cast.hpp" namespace io::network { diff --git a/src/query/typed_value.hpp b/src/query/typed_value.hpp index daf3913a9..c8086da51 100644 --- a/src/query/typed_value.hpp +++ b/src/query/typed_value.hpp @@ -14,7 +14,6 @@ #include "traversal/path.hpp" #include "utils/exceptions/basic_exception.hpp" #include "utils/total_ordering.hpp" -#include "utils/underlying_cast.hpp" namespace query { diff --git a/src/storage/edge_accessor.hpp b/src/storage/edge_accessor.hpp index 698ab7e00..353f4649e 100644 --- a/src/storage/edge_accessor.hpp +++ b/src/storage/edge_accessor.hpp @@ -4,7 +4,6 @@ #include "storage/edge.hpp" #include "storage/record_accessor.hpp" #include "utils/assert.hpp" -#include "utils/reference_wrapper.hpp" // forward declaring the VertexAccessor because it's returned // by some functions diff --git a/src/storage/property_value.hpp b/src/storage/property_value.hpp index 94723fbac..f175d7cc3 100644 --- a/src/storage/property_value.hpp +++ b/src/storage/property_value.hpp @@ -8,7 +8,6 @@ #include "utils/exceptions/stacktrace_exception.hpp" #include "utils/total_ordering.hpp" -#include "utils/underlying_cast.hpp" /** * Encapsulation of a value and it's type encapsulated in a class that has no diff --git a/src/storage/record_accessor.cpp b/src/storage/record_accessor.cpp index 934d9c6a5..37e7a322b 100644 --- a/src/storage/record_accessor.cpp +++ b/src/storage/record_accessor.cpp @@ -1,6 +1,6 @@ -#include "storage/record_accessor.hpp" #include "database/graph_db_accessor.hpp" #include "storage/edge.hpp" +#include "storage/record_accessor.hpp" #include "storage/vertex.hpp" #include "utils/assert.hpp" @@ -48,7 +48,7 @@ GraphDbAccessor &RecordAccessor::db_accessor() const { } template -const uint64_t RecordAccessor::temporary_id() const { +uint64_t RecordAccessor::temporary_id() const { return (uint64_t)vlist_; } diff --git a/src/storage/record_accessor.hpp b/src/storage/record_accessor.hpp index 9330ff5bd..7c2bfe4a5 100644 --- a/src/storage/record_accessor.hpp +++ b/src/storage/record_accessor.hpp @@ -4,7 +4,6 @@ //#include "database/graph_db_accessor.hpp" #include "mvcc/version_list.hpp" #include "storage/property_value.hpp" -#include "utils/pass_key.hpp" #include "storage/property_value_store.hpp" @@ -134,7 +133,7 @@ class RecordAccessor { * * @return See above. */ - const uint64_t temporary_id() const; + uint64_t temporary_id() const; /* * Switches this record accessor to use the latest diff --git a/src/threading/sync/futex.hpp b/src/threading/sync/futex.hpp index d6498a8d4..648baa14f 100644 --- a/src/threading/sync/futex.hpp +++ b/src/threading/sync/futex.hpp @@ -4,9 +4,19 @@ #include #include +#include +#include +#include +#include #include "lock_timeout_error.hpp" #include "utils/cpu_relax.hpp" -#include "utils/sys.hpp" + +namespace sys { +inline int futex(void *addr1, int op, int val1, const struct timespec *timeout, + void *addr2, int val3) { + return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3); +}; +} class Futex { using futex_t = uint32_t; @@ -61,7 +71,7 @@ class Futex { UNLOCKED; } - void lock(const struct timespec* timeout = nullptr) { + void lock(const struct timespec *timeout = nullptr) { // try to fast lock a few times before going to sleep for (size_t i = 0; i < LOCK_RETRIES; ++i) { // try to lock and exit if we succeed @@ -125,7 +135,7 @@ class Futex { private: mutex_t mutex; - int futex_wait(int value, const struct timespec* timeout = nullptr) { + int futex_wait(int value, const struct timespec *timeout = nullptr) { return sys::futex(&mutex.all, FUTEX_WAIT_PRIVATE, value, timeout, nullptr, 0); } diff --git a/src/threading/thread.hpp b/src/threading/thread.hpp index d2d9dcb56..bb773f1fb 100644 --- a/src/threading/thread.hpp +++ b/src/threading/thread.hpp @@ -3,8 +3,6 @@ #include #include -#include "utils/underlying_cast.hpp" - class Thread { static std::atomic thread_counter; diff --git a/src/utils/align.hpp b/src/utils/align.hpp deleted file mode 100644 index 6127d83ae..000000000 --- a/src/utils/align.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -// FROM: A Malloc Tutorial, Marwan Burelle, 2009 - -// align address x to 4 bytes -#define align_4(x) (((((x)-1) >> 2) << 2) + 4) - -// align address x to 8 bytes -#define align_8(x) (((((x)-1) >> 3) << 3) + 8) diff --git a/src/utils/bash_colors.hpp b/src/utils/bash_colors.hpp deleted file mode 100644 index 7526819bc..000000000 --- a/src/utils/bash_colors.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -namespace bash_color { -auto blue = "\033[94m"; -auto green = "\033[92m"; -auto yellow = "\033[93m"; -auto red = "\033[91m"; -auto end = "\033[0m"; -} diff --git a/src/utils/buffer.hpp b/src/utils/buffer.hpp deleted file mode 100644 index 6d9f92e07..000000000 --- a/src/utils/buffer.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -#include "utils/numerics/ceil.hpp" - -class Buffer { - public: - Buffer(size_t capacity, size_t chunk_size) - : capacity(capacity), chunk_size(chunk_size) {} - - Buffer& append(const std::string& string) { - return this->append(string.c_str(), string.size()); - } - - Buffer& append(const char* string, size_t n) { - auto new_size = size() + n; - - if (capacity < new_size) { - capacity = new_size; - data = static_cast(realloc(data, new_size)); - } - - size = new_size; - } - - Buffer& operator<<(const std::string& string) {} - - size_t size() const { return str.size(); } - - private: - size_t size_, capacity, chunk_size; - char* data; -}; diff --git a/src/utils/char_str.hpp b/src/utils/char_str.hpp deleted file mode 100644 index b032b0d13..000000000 --- a/src/utils/char_str.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include "utils/total_ordering.hpp" - -class CharStr : public TotalOrdering { - public: - CharStr(const char *str) : str(str) {} - - std::string to_string() const { return std::string(str); } - - friend bool operator==(const CharStr &lhs, const CharStr &rhs) { - return strcmp(lhs.str, rhs.str) == 0; - } - - friend bool operator<(const CharStr &lhs, const CharStr &rhs) { - return strcmp(lhs.str, rhs.str) < 0; - } - - private: - const char *str; -}; diff --git a/src/utils/eq_wrapper.hpp b/src/utils/eq_wrapper.hpp deleted file mode 100644 index 2a30daee3..000000000 --- a/src/utils/eq_wrapper.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -template -class EqWrapper { - public: - EqWrapper(T t) : t(t) {} - - friend bool operator==(const EqWrapper &a, const EqWrapper &b) { - return a.t == b.t; - } - - friend bool operator!=(const EqWrapper &a, const EqWrapper &b) { - return !(a == b); - } - - T t; -}; diff --git a/src/utils/fswatcher.hpp b/src/utils/fswatcher.hpp index f9d62b3bd..0f0639477 100644 --- a/src/utils/fswatcher.hpp +++ b/src/utils/fswatcher.hpp @@ -8,9 +8,11 @@ #pragma once #include +#include #include #include #include +#include #include #include #include @@ -23,11 +25,26 @@ namespace fs = std::experimental::filesystem; #include "logging/loggable.hpp" #include "utils/algorithm.hpp" #include "utils/assert.hpp" -#include "utils/exceptions/stacktrace_exception.hpp" -#include "utils/linux.hpp" +#include "utils/exceptions/basic_exception.hpp" +#include "utils/likely.hpp" #include "utils/underlying_cast.hpp" namespace utils { +namespace linux_os { +void set_non_blocking(int fd) { + auto flags = fcntl(fd, F_GETFL, 0); + + if (UNLIKELY(flags == -1)) + throw BasicException("Cannot read flags from file descriptor."); + + flags |= O_NONBLOCK; + + auto status = fcntl(fd, F_SETFL, flags); + + if (UNLIKELY(status == -1)) + throw BasicException("Can't set NON_BLOCK flag to file descriptor"); +} +} using ms = std::chrono::milliseconds; @@ -112,7 +129,7 @@ struct WatchDescriptor : public FSEventBase { WatchDescriptor(const fs::path &directory, const FSEventType type) : FSEventBase(directory, type) { debug_assert(fs::is_directory(path), - "The path parameter should be directory"); + "The path parameter should be directory"); } }; diff --git a/src/utils/handle_write.hpp b/src/utils/handle_write.hpp deleted file mode 100644 index 779e4aa8d..000000000 --- a/src/utils/handle_write.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -/* - * Source object is going to be traversed by Writer and Writer will - * write that data into the Destination object. - * - * Writer object defines write format. - */ -template -Destination handle_write(const Source& source) { - Destination destination; - Writer writter(destination); - source.handle(writter); - return destination; -} diff --git a/src/utils/iterator/accessor.hpp b/src/utils/iterator/accessor.hpp deleted file mode 100644 index a77b94aad..000000000 --- a/src/utils/iterator/accessor.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "utils/iterator/range_iterator.hpp" -#include "utils/option.hpp" - -namespace iter { -// Class which turns ranged iterator with next() into accessor. -// T - type of return value -// I - iterator type -template -class OneTimeAccessor { - public: - OneTimeAccessor() : it(Option>()) {} - OneTimeAccessor(I &&it) : it(RangeIterator(std::move(it))) {} - - RangeIterator begin() { return it.take(); } - - RangeIterator end() { return RangeIterator(); } - - private: - Option> it; -}; - -template -auto make_one_time_accessor(I &&iter) { - // Because function isn't receving or in any way using type T from - // OneTimeAccessor compiler can't deduce it thats way there is decltype in - // construction of OneTimeAccessor. Resoulting type of iter.next().take() is - // T. - return OneTimeAccessor(std::move(iter)); -} -} diff --git a/src/utils/iterator/combined.hpp b/src/utils/iterator/combined.hpp deleted file mode 100644 index bdf5cff90..000000000 --- a/src/utils/iterator/combined.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which Combined two iterators IT1 and IT2. -// Both return values T -// T - type of return value -// IT1 - first iterator type -// IT2 - second iterator type -template -class Combined : public IteratorBase, - public Composable> { - public: - Combined() = delete; - - // Combined operation is designed to be used in chained calls which operate - // on a iterator. Combined will in that usecase receive other iterator by - // value and std::move is a optimization for it. - Combined(IT1 &&iter1, IT2 &&iter2) - : iter1(Option(std::move(iter1))), - iter2(Option(std::move(iter2))) {} - - // Return values first from first iterator then from second. - Option next() final { - if (iter1.is_present()) { - auto ret = iter1.get().next(); - if (ret.is_present()) { - return std::move(ret); - } else { - iter1.take(); - } - } - - return iter2.next(); - } - - Count count() final { - return iter1.map_or([](auto &it) { return it.count(); }, 0) + iter2.count(); - } - - private: - Option iter1; - IT2 iter2; -}; - -template -auto make_combined(IT1 &&iter1, IT2 &&iter2) { - // Compiler cant deduce type T. decltype is here to help with it. - return Combined(std::move(iter1), - std::move(iter2)); -} -} diff --git a/src/utils/iterator/composable.hpp b/src/utils/iterator/composable.hpp deleted file mode 100644 index d5e82724a..000000000 --- a/src/utils/iterator/composable.hpp +++ /dev/null @@ -1,190 +0,0 @@ -#pragma once - -#include "utils/crtp.hpp" -#include "utils/iterator/count.hpp" -#include "utils/option.hpp" - -namespace iter { - -template -auto make_map(I &&iter, OP &&op); - -template -auto make_filter(I &&iter, OP &&op); - -template -void for_all(I &&iter, C &&consumer); - -template -auto make_flat_map(I &&iter, OP &&op); - -template -auto make_inspect(I &&iter, OP &&op); - -template -auto make_limited_map(I &&iter, OP &&op); - -template -auto make_virtual(I &&iter); - -template -auto make_combined(IT1 &&iter1, IT2 &&iter2); - -// Class for creating easy composable iterators fo querying. -// -// Derived - type of derived class -// T - return type -template -class Composable : public Crtp { - // Moves self - Derived &&move() { return std::move(this->derived()); } - - public: - auto virtualize() { return iter::make_virtual(move()); } - - template - auto combine(IT &&it) { - return iter::make_combined(move(), std::move(it)); - } - - template - auto map(OP &&op) { - return iter::make_map(move(), std::move(op)); - } - - template - auto filter(OP &&op) { - return iter::make_filter(move(), std::move(op)); - } - - // Replaces every item with item taken from n if it exists. - template - auto replace(Option &n) { - return iter::make_limited_map( - move(), [&](auto v) mutable { return std::move(n); }); - } - - // For all items calls OP. - template - void for_all(OP &&op) { - iter::for_all(move(), std::move(op)); - } - - // All items must satisfy given predicate for this function to return true. - // Otherwise stops calling predicate on firts false and returns fasle. - template - bool all(OP &&op) { - auto iter = move(); - auto e = iter.next(); - while (e.is_present()) { - if (!op(e.take())) { - return false; - } - e = iter.next(); - } - return true; - } - - // !! MEMGRAPH specific composable filters - // TODO: isolate, but it is not trivial because this class - // is a base for other generic classes - - // Maps with call to method to() and filters with call to fill. - auto to() { - return map([](auto er) { return er.to(); }).fill(); - } - - // Maps with call to method from() and filters with call to fill. - auto from() { - return map([](auto er) { return er.from(); }).fill(); - } - - // Combines out iterators into one iterator. - auto out() { - return iter::make_flat_map( - move(), [](auto vr) { return vr.out().fill(); }); - } - - auto in() { - return iter::make_flat_map(move(), - [](auto vr) { return vr.in().fill(); }); - } - - // Filters with label on from vertex. - template - auto from_label(LABEL const &label) { - return filter([&](auto &ra) { - auto va = ra.from(); - return va.fill() && va.has_label(label); - }); - } - - // Calls update on values and returns result. - auto update() { - return map([](auto ar) { return ar.update(); }); - } - - // Filters with property under given key - template - auto has_property(KEY &key) { - return filter([&](auto &va) { return !va.at(key).is_empty(); }); - } - - // Filters with property under given key - template - auto has_property(KEY &key, PROP const &prop) { - return filter([&](auto &va) { return va.at(key) == prop; }); - } - - // Copy-s pasing value to t before they are returned. - auto clone_to(Option &t) { - return iter::make_inspect( - move(), [&](auto &v) mutable { t = Option(v); }); - } - - // auto clone_to(Option &t) - // { - // return iter::make_inspect( - // move(), [&](auto &e) mutable { t = Option(e); }); - // } - - // Filters with call to method fill() - auto fill() { - return filter([](auto &ra) { return ra.fill(); }); - } - - // Filters with type - template - auto type(TYPE const &type) { - return filter([&](auto &ra) { return ra.edge_type() == type; }); - } - - // Filters with label. - template - auto label(LABEL const &label) { - return filter([&](auto &va) { return va.has_label(label); }); - } - - // Filters out vertices which are connected. - auto isolated() { - return filter([&](auto &element) { return element.isolated(); }); - } - - // filter elements based on properties (all properties have to match) - // TRANSACTION -> transaction - // PROPERTIES -> [(name, property)] - template - auto properties_filter(TRANSACTION &t, PROPERTIES &properties) { - return filter([&](auto &element) { - for (auto &name_value : properties) { - auto property_key = t.vertex_property_key( - name_value.first, name_value.second.key.flags()); - if (!element.properties().contains(property_key)) return false; - auto vertex_property_value = element.at(property_key); - if (!(vertex_property_value == name_value.second)) return false; - } - return true; - }); - } -}; -} diff --git a/src/utils/iterator/count.hpp b/src/utils/iterator/count.hpp deleted file mode 100644 index ab9ff83d5..000000000 --- a/src/utils/iterator/count.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "utils/numerics/saturate.hpp" -#include "utils/total_ordering.hpp" - -// Represents number of to be returned elements from iterator. Where acutal -// number is probably somwhere in [min,max]. -// NOTE: Experimental -class Count : public TotalOrdering { - public: - Count(size_t exact) : min(exact), max(exact) {} - - Count(size_t min, size_t max) : min(min), max(max) {} - - Count min_zero() const { return Count(0, max); } - - size_t avg() const { return ((max - min) >> 1) + min; } - - friend constexpr bool operator<(const Count &lhs, const Count &rhs) { - return lhs.avg() < rhs.avg(); - } - - friend constexpr bool operator==(const Count &lhs, const Count &rhs) { - return lhs.avg() == rhs.avg(); - } - - friend Count operator+(const Count &lhs, const Count &rhs) { - return Count(num::saturating_add(lhs.min, rhs.min), - num::saturating_add(lhs.max, rhs.max)); - } - - size_t min; - size_t max; -}; diff --git a/src/utils/iterator/filter.hpp b/src/utils/iterator/filter.hpp deleted file mode 100644 index f71062c0b..000000000 --- a/src/utils/iterator/filter.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which filters values T returned by I iterator if OP returns true for -// them. -// T - type of return value -// I - iterator type -// OP - type of filter function. OP: T& -> bool -template -class Filter : public IteratorBase, public Composable> { - public: - Filter() = delete; - - // Filter operation is designed to be used in chained calls which operate on - // a - // iterator. Filter will in that usecase receive other iterator by value and - // std::move is a optimization for it. - Filter(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} - - // Return values for which filter return true. - Option next() final { - auto item = Option(); - do { - item = iter.next(); - if (!item.is_present()) { - return Option(); - } - } while (!op(item.get())); - - return std::move(item); - } - - Count count() final { return iter.count().min_zero(); } - - private: - I iter; - OP op; -}; - -template -auto make_filter(I &&iter, OP &&op) { - // Compiler cant deduce type T. decltype is here to help with it. - return Filter(std::move(iter), - std::move(op)); -} -} diff --git a/src/utils/iterator/flat_map.hpp b/src/utils/iterator/flat_map.hpp deleted file mode 100644 index 58760ca09..000000000 --- a/src/utils/iterator/flat_map.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which maps values returned by I iterator into iterators of type J -// ,which -// return value of type T, with function OP. -// function. -// T - type of return value -// I - iterator type -// J - iterator type returned from OP -// OP - type of mapper function -// TODO: Split into flat operation and map operation. -template -class FlatMap : public IteratorBase, - public Composable> { - public: - FlatMap() = delete; - - // FlatMap operation is designed to be used in chained calls which operate - // on a - // iterator. FlatMap will in that usecase receive other iterator by value - // and - // std::move is a optimization for it. - FlatMap(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} - - FlatMap(FlatMap &&m) - : iter(std::move(m.iter)), - op(std::move(m.op)), - sub_iter(std::move(m.sub_iter)) {} - - ~FlatMap() final {} - - Option next() final { - do { - if (!sub_iter.is_present()) { - auto item = iter.next(); - if (item.is_present()) { - sub_iter = Option(op(item.take())); - } else { - return Option(); - } - } - - auto item = sub_iter.get().next(); - if (item.is_present()) { - return std::move(item); - } else { - sub_iter.take(); - } - } while (true); - } - - Count count() final { - // TODO: Correct count, are at least correcter - return iter.count(); - } - - private: - I iter; - Option sub_iter; - OP op; -}; - -template -auto make_flat_map(I &&iter, OP &&op) { - // Compiler cant deduce type T and J. decltype is here to help with it. - return FlatMap(std::move(iter), - std::move(op)); -} -} diff --git a/src/utils/iterator/for_all.hpp b/src/utils/iterator/for_all.hpp deleted file mode 100644 index 4a4de5273..000000000 --- a/src/utils/iterator/for_all.hpp +++ /dev/null @@ -1,36 +0,0 @@ - -#pragma once - -#include -#include "utils/option.hpp" - -namespace iter { -template -void for_all(I &&iter, C &&consumer) { - auto e = iter.next(); - while (e.is_present()) { - consumer(e.take()); - e = iter.next(); - } -} - -template -void for_all(std::unique_ptr &&iter, C &&consumer) { - auto e = iter->next(); - while (e.is_present()) { - consumer(e.take()); - e = iter->next(); - } -} - -template -void find(I iter, C &&consumer) { - auto e = iter.next(); - while (e.is_present()) { - if (consumer(e.take())) { - return; - } - e = iter.next(); - } -} -} diff --git a/src/utils/iterator/inspect.hpp b/src/utils/iterator/inspect.hpp deleted file mode 100644 index 330c2f169..000000000 --- a/src/utils/iterator/inspect.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which inspects values returned by I iterator -// before passing them as a result. -// function. -// T - type of return value -// I - iterator type -// OP - type of inspector function. OP: T&->void -template -class Inspect : public IteratorBase, - public Composable> { - public: - Inspect() = delete; - - // Inspect operation is designed to be used - // in chained calls which operate on an - // iterator. Inspect will in that usecase - // receive other iterator by value and - // std::move is a optimization for it. - Inspect(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} - - Inspect(Inspect &&m) : iter(std::move(m.iter)), op(std::move(m.op)) {} - - ~Inspect() final {} - - Option next() final { - auto item = iter.next(); - if (item.is_present()) { - op(item.get()); - return std::move(item); - } else { - return Option(); - } - } - - Count count() final { return iter.count(); } - - private: - I iter; - OP op; -}; - -template -auto make_inspect(I &&iter, OP &&op) { - // Compiler cant deduce type T. decltype is here to help with it. - return Inspect(std::move(iter), - std::move(op)); -} -} diff --git a/src/utils/iterator/iterator.hpp b/src/utils/iterator/iterator.hpp deleted file mode 100644 index e47748a7c..000000000 --- a/src/utils/iterator/iterator.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "utils/iterator/accessor.hpp" -#include "utils/iterator/combined.hpp" -#include "utils/iterator/count.hpp" -#include "utils/iterator/filter.hpp" -#include "utils/iterator/flat_map.hpp" -#include "utils/iterator/for_all.hpp" -#include "utils/iterator/inspect.hpp" -#include "utils/iterator/iterator_accessor.hpp" -#include "utils/iterator/iterator_base.hpp" -#include "utils/iterator/lambda_iterator.hpp" -#include "utils/iterator/limited_map.hpp" -#include "utils/iterator/map.hpp" -#include "utils/iterator/range_iterator.hpp" -#include "utils/iterator/virtual_iter.hpp" diff --git a/src/utils/iterator/iterator_accessor.hpp b/src/utils/iterator/iterator_accessor.hpp deleted file mode 100644 index 8fc4c32d1..000000000 --- a/src/utils/iterator/iterator_accessor.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which turns accessor int next() based iterator. -// T - type of return value -// I - iterator type gotten from accessor -// A - accessor type -template -class IteratorAccessor : public IteratorBase, - public Composable> { - public: - IteratorAccessor() = delete; - - IteratorAccessor(A &&acc) - : begin(std::move(acc.begin())), acc(std::forward(acc)), returned(0) {} - - IteratorAccessor(IteratorAccessor &&other) - : begin(std::move(other.begin)), - acc(std::forward(other.acc)), - returned(other.returned) {} - - ~IteratorAccessor() final {} - - // Iter(const Iter &other) = delete; - // Iter(Iter &&other) : - // begin(std::move(other.begin)),end(std::move(other.end)) {}; - - Option next() final { - if (begin != acc.end()) { - auto ret = Option(&(*(begin.operator->()))); - begin++; - returned++; - return ret; - } else { - return Option(); - } - } - - Count count() final { - auto size = acc.size(); - if (size > returned) { - return Count(0); - } else { - return Count(size - returned); - } - } - - private: - I begin; - A acc; - size_t returned; -}; - -// TODO: Join to make functions into one -template -auto make_iter(A &&acc) { - // Compiler cant deduce types T and I. decltype are here to help with it. - return IteratorAccessor()))), - decltype(acc.begin()), A>(std::move(acc)); -} - -template -auto make_iter_ref(A &acc) { - // Compiler cant deduce types T and I. decltype are here to help with it. - return IteratorAccessor()))), - decltype(acc.begin()), A &>(acc); -} -} diff --git a/src/utils/iterator/iterator_base.hpp b/src/utils/iterator/iterator_base.hpp deleted file mode 100644 index 3b368c55e..000000000 --- a/src/utils/iterator/iterator_base.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "utils/iterator/count.hpp" -#include "utils/option.hpp" - -// Base iterator for next() kind iterator. -// T - type of return value -template -class IteratorBase { - public: - virtual ~IteratorBase(){}; - - virtual Option next() = 0; - - virtual Count count() = 0; -}; diff --git a/src/utils/iterator/lambda_iterator.hpp b/src/utils/iterator/lambda_iterator.hpp deleted file mode 100644 index bf1eaa4a2..000000000 --- a/src/utils/iterator/lambda_iterator.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { -// Wraps lambda into interator with next(). -// T - type of return value -// F - type of wraped lambda -template -class LambdaIterator : public IteratorBase, - public Composable> { - public: - LambdaIterator(F &&f, size_t count) : func(std::move(f)), _count(count) {} - - LambdaIterator(LambdaIterator &&other) - : func(std::move(other.func)), _count(other._count) {} - - ~LambdaIterator() final {} - - Option next() final { - _count = _count > 0 ? _count - 1 : 0; - return func(); - } - - Count count() final { return Count(_count); } - - private: - F func; - size_t _count; -}; - -// Wraps lambda which returns options as an iterator. -template -auto make_iterator(F &&f) { - return make_iterator(std::move(f), ~((size_t)0)); -} - -// Wraps lambda which returns options as an iterator. -template -auto make_iterator(F &&f, size_t count) { - // Because function isn't receving or in any way using type T from - // FunctionIterator compiler can't deduce it thats way there is decltype in - // construction of FunctionIterator. Resoulting type of iter.next().take() - // is T. - return LambdaIterator(std::move(f), count); -} -} diff --git a/src/utils/iterator/limited_map.hpp b/src/utils/iterator/limited_map.hpp deleted file mode 100644 index 3f430981a..000000000 --- a/src/utils/iterator/limited_map.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which maps values returned by I iterator into value of type T with OP -// function and ends when op returns empty optional. -// T - type of return value -// I - iterator type -// OP - type of mapper function. OP: V -> Option -template -class LimitedMap : public IteratorBase, - public Composable> { - public: - LimitedMap() = delete; - - // LimitedMap operation is designed to be used in chained calls which - // operate on a - // iterator. LimitedMap will in that usecase receive other iterator by value - // and - // std::move is a optimization for it. - LimitedMap(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} - - LimitedMap(LimitedMap &&m) : iter(std::move(m.iter)), op(std::move(m.op)) {} - - ~LimitedMap() final {} - - Option next() final { - auto item = iter.next(); - if (item.is_present()) { - return op(item.take()); - } else { - return Option(); - } - } - - Count count() final { return iter.count(); } - - private: - I iter; - OP op; -}; - -template -auto make_limited_map(I &&iter, OP &&op) { - // Compiler cant deduce type T. decltype is here to help with it. - return LimitedMap( - std::move(iter), std::move(op)); -} -} diff --git a/src/utils/iterator/map.hpp b/src/utils/iterator/map.hpp deleted file mode 100644 index 2a1b7f483..000000000 --- a/src/utils/iterator/map.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which maps values returned by I iterator into value of type T with OP -// function. -// T - type of return value -// I - iterator type -// OP - type of mapper function -template -class Map : public IteratorBase, public Composable> { - public: - Map() = delete; - - // Map operation is designed to be used in chained calls which operate on a - // iterator. Map will in that usecase receive other iterator by value and - // std::move is a optimization for it. - Map(I &&iter, OP &&op) : iter(std::move(iter)), op(std::move(op)) {} - - Map(Map &&m) : iter(std::move(m.iter)), op(std::move(m.op)) {} - - ~Map() final {} - - Option next() final { - auto item = iter.next(); - if (item.is_present()) { - return Option(op(item.take())); - } else { - return Option(); - } - } - - Count count() final { return iter.count(); } - - private: - I iter; - OP op; -}; - -template -auto make_map(I &&iter, OP &&op) { - // Compiler cant deduce type T. decltype is here to help with it. - return Map(std::move(iter), - std::move(op)); -} -} diff --git a/src/utils/iterator/query.hpp b/src/utils/iterator/query.hpp deleted file mode 100644 index 11f019ba6..000000000 --- a/src/utils/iterator/query.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "storage/vertex_accessor.hpp" -#include "utils/iterator/iterator.hpp" -#include "utils/option.hpp" - -namespace query_help { - -template -bool fill(A &a) { - return a.fill(); -} -}; - -// Base iterator for next() kind iterator. -// Vertex::Accessor - type of return value -template <> -class IteratorBase { - public: - virtual Option next() = 0; - - auto fill() { return iter::make_filter(std::move(*this), query_help::fill); } -}; diff --git a/src/utils/iterator/range_iterator.hpp b/src/utils/iterator/range_iterator.hpp deleted file mode 100644 index c60aa160e..000000000 --- a/src/utils/iterator/range_iterator.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "utils/assert.hpp" -#include "utils/option.hpp" - -namespace iter { - -// Class which wraps iterator with next() into C++ iterator. -// T - type of return value -// I - iterator type -template -class RangeIterator { - public: - RangeIterator() : iter(Option()), value(Option()){}; - - RangeIterator(I &&iter) - : value(iter.next()), iter(Option(std::move(iter))) {} - - T &operator*() { - debug_assert(value.is_present(), "No value."); - return value.get(); - } - - T *operator->() { - debug_assert(value.is_present(), "No value."); - return &value.get(); - } - - operator T &() { - debug_assert(value.is_present(), "No value."); - return value.get(); - } - - RangeIterator &operator++() { - debug_assert(iter.is_present(), "No value."); - value = iter.get().next(); - return (*this); - } - - RangeIterator &operator++(int) { return operator++(); } - - friend bool operator==(const RangeIterator &a, const RangeIterator &b) { - return a.value.is_present() == b.value.is_present(); - } - - friend bool operator!=(const RangeIterator &a, const RangeIterator &b) { - return !(a == b); - } - - private: - Option iter; - Option value; -}; - -template -auto make_range_iterator(I &&iter) { - // Because this function isn't receving or in any way using type T from - // RangeIterator, compiler can't deduce it. That is the reason why - // there is decltype in construction of RangeIterator. - // declytype(iter.next().take()) is T. - return RangeIterator(std::move(iter)); -} -} diff --git a/src/utils/iterator/virtual_iter.hpp b/src/utils/iterator/virtual_iter.hpp deleted file mode 100644 index a7eefe20e..000000000 --- a/src/utils/iterator/virtual_iter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "utils/iterator/composable.hpp" -#include "utils/iterator/iterator_base.hpp" - -namespace iter { - -// Class which wraps iterator and hides it's type. It actualy does this by -// dynamicly allocating iterator on heap. -// T - type of return value -template -class Virtual : public Composable> { - public: - Virtual() = delete; - - // Virtual operation is designed to be used in chained calls which operate - // on a - // iterator. Virtual will in that usecase receive other iterator by value - // and - // std::move is a optimization for it. - - template - Virtual(I &&iter) : it(std::make_unique(std::move(iter))) {} - - Virtual(Virtual &&m) : it(std::move(m.it)) {} - - ~Virtual() {} - - Option next() { return it.get()->next(); } - - Count count() { return it.get()->count(); } - - private: - std::unique_ptr> it; -}; - -template -auto make_virtual(I &&iter) { - // Compiler can't deduce type T. decltype is here to help with it. - return Virtual(std::move(iter)); -} -} diff --git a/src/utils/linux.hpp b/src/utils/linux.hpp deleted file mode 100644 index 11fdd8dde..000000000 --- a/src/utils/linux.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once - -// ** Books ** -// http://instructor.sdu.edu.kz/~konst/sysprog2015fall/readings/linux%20system%20programming/The%20Linux%20Programming%20Interface-Michael%20Kerrisk.pdf - -// ** Documentation ** -// http://man7.org/linux/man-pages/man2/read.2.html -// http://man7.org/linux/man-pages/man2/select.2.html -// http://man7.org/linux/man-pages/man2/fcntl.2.html - -// ** Community ** -// http://stackoverflow.com/questions/5616092/non-blocking-call-for-reading-descriptor -// http://stackoverflow.com/questions/2917881/how-to-implement-a-timeout-in-read-function-call - -#include -#include - -#include "utils/exceptions/not_yet_implemented.hpp" -#include "utils/exceptions/stacktrace_exception.hpp" -#include "utils/likely.hpp" - -namespace linux_os { -class LinuxException : public StacktraceException { - using StacktraceException::StacktraceException; -}; - -/** - * Sets non blocking flag to a file descriptor. - */ -void set_non_blocking(int fd) { - auto flags = fcntl(fd, F_GETFL, 0); - - if (UNLIKELY(flags == -1)) - throw LinuxException("Cannot read flags from file descriptor."); - - flags |= O_NONBLOCK; - - auto status = fcntl(fd, F_SETFL, flags); - - if (UNLIKELY(status == -1)) - throw LinuxException("Can't set NON_BLOCK flag to file descriptor"); -} - -/** - * Reads a file descriptor with timeout. - */ -void tread() { throw NotYetImplemented(); } -} diff --git a/src/utils/mark_ref.hpp b/src/utils/mark_ref.hpp deleted file mode 100644 index 20a93dfbf..000000000 --- a/src/utils/mark_ref.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -template -struct MarkRef { - MarkRef() = default; - MarkRef(MarkRef&) = default; - MarkRef(MarkRef&&) = default; - - bool is_marked() const { return ptr & 0x1L; } - - bool set_mark() { return ptr |= 0x1L; } - - bool clear_mark() { return ptr &= ~0x1L; } - - T* get() const { return reinterpret_cast(ptr & ~0x1L); } - - T& operator*() { return *get(); } - T* operator->() { return get(); } - - operator T*() { return get(); } - - uintptr_t ptr; -}; diff --git a/src/utils/order.hpp b/src/utils/order.hpp deleted file mode 100644 index 8d5e63d28..000000000 --- a/src/utils/order.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Defines ordering of data -enum Order : uint8_t { - None = 0, - Ascending = 1, - Descending = 2, -}; diff --git a/src/utils/pass_key.hpp b/src/utils/pass_key.hpp deleted file mode 100644 index 37a1021a7..000000000 --- a/src/utils/pass_key.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// -// Copyright 2017 Memgraph -// Created by Marko Budiselic -// -// SOURCES: -// http://arne-mertz.de/2016/10/passkey-idiom/ -// http://stackoverflow.com/questions/3217390/clean-c-granular-friend-equivalent-answer-attorney-client-idiom - -#pragma once - -template -class PassKey { - friend T; - - private: - // default constructor has to be manually defined otherwise = default - // would allow aggregate initialization to bypass default constructor - // both, default and copy constructors have to be user-defined - // otherwise are public by default - PassKey() {} -}; diff --git a/src/utils/reference_wrapper.hpp b/src/utils/reference_wrapper.hpp deleted file mode 100644 index 1721949f6..000000000 --- a/src/utils/reference_wrapper.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -// ReferenceWrapper was created because std::reference_wrapper -// wasn't copyable -// Implementation has been taken from: -// http://en.cppreference.com/w/cpp/utility/functional/reference_wrapper -// TODO: once the c++ implementation will have proper implementation -// this class should be deleted and replaced with std::reference_wrapper - -template -class ReferenceWrapper { - public: - // types - typedef T type; - - // construct/copy/destroy - ReferenceWrapper(T &ref) noexcept : _ptr(std::addressof(ref)) {} - ReferenceWrapper(T &&) = delete; - ReferenceWrapper(const ReferenceWrapper &) noexcept = default; - - // assignment - ReferenceWrapper &operator=(const ReferenceWrapper &x) noexcept = default; - - // access - operator T &() const noexcept { return *_ptr; } - T &get() const noexcept { return *_ptr; } - - // template - // typename std::result_of::type - // operator()(ArgTypes &&... args) const - // { - // return std::invoke(get(), std::forward(args)...); - // } - - private: - T *_ptr; -}; diff --git a/src/utils/stream_wrapper.hpp b/src/utils/stream_wrapper.hpp deleted file mode 100644 index 4581ae8c0..000000000 --- a/src/utils/stream_wrapper.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -// Wraps stream with convinient methods which need only one method: -// write (const char* s, n); -template -class StreamWrapper { - public: - StreamWrapper() = delete; - StreamWrapper(STREAM &s) : stream(s) {} - - void write(const unsigned char value) { - stream.write(reinterpret_cast(&value), 1); - } - - void write(const unsigned char *value, size_t n) { - stream.write(reinterpret_cast(value), n); - } - - private: - STREAM &stream; -}; diff --git a/src/utils/string_buffer.hpp b/src/utils/string_buffer.hpp deleted file mode 100644 index 73cbdacdb..000000000 --- a/src/utils/string_buffer.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include - -namespace utils { - -class StringBuffer { - public: - StringBuffer() = default; - ~StringBuffer() = default; - - StringBuffer(const StringBuffer &) = delete; - StringBuffer(StringBuffer &&) = default; - - StringBuffer &operator=(const StringBuffer &) = delete; - StringBuffer &operator=(StringBuffer &&) = default; - - StringBuffer(std::string::size_type count) { resize(count); } - - void resize(std::string::size_type count) { data.resize(count); } - - StringBuffer &operator<<(const std::string &str) { - data += str; - return *this; - } - - StringBuffer &operator<<(const char *str) { - data += str; - return *this; - } - - StringBuffer &operator<<(char c) { - data += c; - return *this; - } - - std::string &str() { return data; } - - private: - std::string data; -}; -} diff --git a/src/utils/sys.hpp b/src/utils/sys.hpp deleted file mode 100644 index 959d2d1dd..000000000 --- a/src/utils/sys.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace sys { -// Code from stackoverflow: -// http://stackoverflow.com/questions/676787/how-to-do-fsync-on-an-ofstream -// Extracts FILE* from streams in std. -inline int GetFileDescriptor(std::filebuf &filebuf) { - class my_filebuf : public std::filebuf { - public: - int handle() { return _M_file.fd(); } - }; - - return static_cast(filebuf).handle(); -} - -inline int futex(void *addr1, int op, int val1, const struct timespec *timeout, - void *addr2, int val3) { - return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3); -}; - -// Ensures that everything written to file will be writen on disk when the -// function call returns. !=0 if error occured -template -inline size_t flush_file_to_disk(STREAM &file) { - file.flush(); - if (fsync(GetFileDescriptor(*file.rdbuf())) == 0) { - return 0; - } - - return errno; -}; - -// True if succesffull -inline bool ensure_directory_exists(std::string const &path) { - struct stat st = {0}; - - if (stat(path.c_str(), &st) == -1) { - return mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == 0; - } - return true; -} -}; diff --git a/src/utils/total_ordering.hpp b/src/utils/total_ordering.hpp index 5a54a417d..5295ad32f 100644 --- a/src/utils/total_ordering.hpp +++ b/src/utils/total_ordering.hpp @@ -11,19 +11,54 @@ */ template struct TotalOrdering { - friend constexpr TReturn operator!=(const TLhs &a, const TRhs &b) { + friend constexpr TReturn operator!=(const TLhs& a, const TRhs& b) { return !(a == b); } - friend constexpr TReturn operator<=(const TLhs &a, const TRhs &b) { + friend constexpr TReturn operator<=(const TLhs& a, const TRhs& b) { return a < b || a == b; } - friend constexpr TReturn operator>(const TLhs &a, const TRhs &b) { + friend constexpr TReturn operator>(const TLhs& a, const TRhs& b) { return !(a <= b); } - friend constexpr TReturn operator>=(const TLhs &a, const TRhs &b) { + friend constexpr TReturn operator>=(const TLhs& a, const TRhs& b) { + return !(a < b); + } +}; + +template +struct TotalOrderingWith { + friend constexpr bool operator!=(const Derived& a, const T& b) { + return !(a == b); + } + + friend constexpr bool operator<=(const Derived& a, const T& b) { + return a < b || a == b; + } + + friend constexpr bool operator>(const Derived& a, const T& b) { + return !(a <= b); + } + + friend constexpr bool operator>=(const Derived& a, const T& b) { + return !(a < b); + } + + friend constexpr bool operator!=(const T& a, const Derived& b) { + return !(a == b); + } + + friend constexpr bool operator<=(const T& a, const Derived& b) { + return a < b || a == b; + } + + friend constexpr bool operator>(const T& a, const Derived& b) { + return !(a <= b); + } + + friend constexpr bool operator>=(const T& a, const Derived& b) { return !(a < b); } }; diff --git a/src/utils/total_ordering_with.hpp b/src/utils/total_ordering_with.hpp deleted file mode 100644 index de5bdd0cd..000000000 --- a/src/utils/total_ordering_with.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -template -struct TotalOrderingWith { - friend constexpr bool operator!=(const Derived& a, const T& b) { - return !(a == b); - } - - friend constexpr bool operator<=(const Derived& a, const T& b) { - return a < b || a == b; - } - - friend constexpr bool operator>(const Derived& a, const T& b) { - return !(a <= b); - } - - friend constexpr bool operator>=(const Derived& a, const T& b) { - return !(a < b); - } - - friend constexpr bool operator!=(const T& a, const Derived& b) { - return !(a == b); - } - - friend constexpr bool operator<=(const T& a, const Derived& b) { - return a < b || a == b; - } - - friend constexpr bool operator>(const T& a, const Derived& b) { - return !(a <= b); - } - - friend constexpr bool operator>=(const T& a, const Derived& b) { - return !(a < b); - } -}; diff --git a/src/utils/void.hpp b/src/utils/void.hpp deleted file mode 100644 index faf378978..000000000 --- a/src/utils/void.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include "utils/total_ordering.hpp" - -// Type which represents nothing. -class Void : public TotalOrdering { - public: - friend bool operator<(const Void &lhs, const Void &rhs) { return false; } - - friend bool operator==(const Void &lhs, const Void &rhs) { return true; } -}; - -static Void _void = {};