From 8c4c618cc0cc9a3814fd21cad556851f0e81ad01 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 6 Feb 2024 00:20:37 -0500 Subject: [PATCH] refractor a bit --- CMakeLists.txt | 16 +- include/blt/{std => fs}/filesystem.h | 0 include/blt/{std => fs}/loader.h | 0 include/blt/{nbt => fs}/nbt.h | 2 +- include/blt/{nbt => fs}/nbt_block.h | 0 include/blt/std/expected.h | 377 ++++++++++++++++++++ include/blt/std/ranges.h | 170 +++++++++ include/blt/std/utility.h | 515 +-------------------------- src/blt/{std => fs}/filesystem.cpp | 2 +- src/blt/{nbt => fs}/nbt.cpp | 2 +- src/blt/{nbt => fs}/nbt_block.cpp | 2 +- src/blt/parse/obj_loader.cpp | 2 +- src/blt/std/loader.cpp | 2 +- src/blt/std/system.cpp | 4 +- tests/src/nbt_tests.cpp | 4 +- 15 files changed, 569 insertions(+), 529 deletions(-) rename include/blt/{std => fs}/filesystem.h (100%) rename include/blt/{std => fs}/loader.h (100%) rename include/blt/{nbt => fs}/nbt.h (99%) rename include/blt/{nbt => fs}/nbt_block.h (100%) create mode 100644 include/blt/std/expected.h create mode 100644 include/blt/std/ranges.h rename src/blt/{std => fs}/filesystem.cpp (98%) rename src/blt/{nbt => fs}/nbt.cpp (98%) rename src/blt/{nbt => fs}/nbt_block.cpp (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f87c050..be81026 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.5) -set(BLT_VERSION 0.10.1) +set(BLT_VERSION 0.11.3) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) @@ -15,7 +15,7 @@ option(ENABLE_TSAN "Enable the thread data race sanitizer" OFF) option(BUILD_STD "Build the BLT standard utilities." ON) option(BUILD_PROFILING "Build the BLT profiler extension" ON) -option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON) +option(BUILD_FS "Build the BLT FS utilities including the NBT + eNBT extension" ON) option(BUILD_PARSE "Build the BLT parsers" ON) option(BUILD_TESTS "Build the BLT test set" OFF) @@ -45,11 +45,11 @@ else() set(PROFILING_FILES "") endif() -if(${BUILD_NBT}) - message("Building NBT") - file(GLOB_RECURSE NBT_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/nbt/*.cpp") +if(${BUILD_FS}) + message("Building FS") + file(GLOB_RECURSE FS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/fs/*.cpp") else() - set(NBT_FILES "") + set(FS_FILES "") endif() if(${BUILD_PARSE}) @@ -78,10 +78,12 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/config/) message("Standard Files ${STD_FILES}") message("Profiler Files ${PROFILING_FILES}") +message("FS Files ${FS_FILES}") +message("Parser Files ${PARSE_FILES}") message("Source: ${CMAKE_SOURCE_DIR}") message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}") -add_library(${BLT_TARGET} ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES} ${PARSE_FILES}) +add_library(${BLT_TARGET} ${STD_FILES} ${PROFILING_FILES} ${FS_FILES} ${PARSE_FILES}) target_include_directories(${BLT_TARGET} PUBLIC include/) target_include_directories(${BLT_TARGET} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config/) diff --git a/include/blt/std/filesystem.h b/include/blt/fs/filesystem.h similarity index 100% rename from include/blt/std/filesystem.h rename to include/blt/fs/filesystem.h diff --git a/include/blt/std/loader.h b/include/blt/fs/loader.h similarity index 100% rename from include/blt/std/loader.h rename to include/blt/fs/loader.h diff --git a/include/blt/nbt/nbt.h b/include/blt/fs/nbt.h similarity index 99% rename from include/blt/nbt/nbt.h rename to include/blt/fs/nbt.h index fb51440..bc53ea8 100755 --- a/include/blt/nbt/nbt.h +++ b/include/blt/fs/nbt.h @@ -14,7 +14,7 @@ #include #include "blt/std/format.h" -#include "blt/std/filesystem.h" +#include "blt/fs/filesystem.h" #include "blt/std/logging.h" #include "blt/std/memory.h" diff --git a/include/blt/nbt/nbt_block.h b/include/blt/fs/nbt_block.h similarity index 100% rename from include/blt/nbt/nbt_block.h rename to include/blt/fs/nbt_block.h diff --git a/include/blt/std/expected.h b/include/blt/std/expected.h new file mode 100644 index 0000000..737b02d --- /dev/null +++ b/include/blt/std/expected.h @@ -0,0 +1,377 @@ +#pragma once +/* + * Created by Brett on 06/02/24. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_EXPECTED_H +#define BLT_EXPECTED_H + +#include +#include +#include +#include + +namespace blt +{ + struct unexpect_t + { + explicit unexpect_t() = default; + }; + + inline constexpr unexpect_t unexpect{}; + + template + using remove_cvref_t = std::remove_reference_t>; + + template + class unexpected + { + private: + E e; + public: + constexpr unexpected(const unexpected&) = default; + + constexpr unexpected(unexpected&&) = default; + + template, unexpected> && !std::is_same_v, std::in_place_t> && + std::is_constructible_v, bool> = true> + constexpr explicit unexpected(Err&& e): e(std::forward(e)) + {} + + template, bool> = true> + constexpr explicit unexpected(std::in_place_t, Args&& ... args): e(std::forward(args)...) + {} + + template&, Args...>, bool> = true> + constexpr explicit unexpected(std::in_place_t, std::initializer_list il, Args&& ... args): e(il, std::forward(args)...) + {} + + constexpr const E& error() const& noexcept + { + return e; + } + + constexpr E& error()& noexcept + { + return e; + } + + constexpr const E&& error() const&& noexcept + { + return e; + } + + constexpr E&& error()&& noexcept + { + return e; + } + + constexpr void swap(unexpected& other) noexcept(std::is_nothrow_swappable_v) + { + std::swap(error(), other.error()); + } + + template + inline friend constexpr bool operator==(const unexpected& x, const unexpected & y) + { + return x.error() == y.error(); + } + + friend constexpr void swap(unexpected& x, unexpected& y) noexcept(noexcept(x.swap(y))) + {} + }; + + template + unexpected(E) -> unexpected; + + template + class bad_expected_access : public std::exception + { + private: + E e; + public: + explicit bad_expected_access(E e): e(std::move(e)) + {} + + const E& error() const& noexcept + { return e; } + + E& error()& noexcept + { return e; } + + const E&& error() const&& noexcept + { return e; } + + E&& error()&& noexcept + { return e; } + + [[nodiscard]] const char* what() const noexcept override + { return "blt::expected does not contain a value!"; } + + }; + + template> + class expected + { + protected: + std::variant v; + + template + inline static constexpr bool eight_insanity_v = + std::is_constructible_v&> || std::is_constructible_v> || + std::is_constructible_v&> || std::is_constructible_v> || + std::is_convertible_v&, T> || std::is_convertible_v, T> || + std::is_convertible_v&, T> || std::is_convertible_v, T>; + + template + inline static constexpr bool four_insanity_v = + std::is_constructible_v, expected&> || std::is_constructible_v, expected> || + std::is_constructible_v, const expected&> || std::is_constructible_v, const expected>; + + public: + template, bool> = true> + constexpr expected() noexcept: v(T()) + {} + + constexpr expected(const expected& copy) = delete; + + constexpr expected(expected&& move) noexcept: v(move ? std::move(*move) : std::move(move.error())) + {} + + /* + * (4)...(5) + */ + template, class GF = const G&, std::enable_if_t< + (!std::is_convertible_v || !std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && + std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> + + constexpr explicit expected(const expected& other): + v(other.has_value() ? std::forward(*other) : std::forward(other.error())) + {} + + template || !std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && + std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> + + constexpr explicit expected(expected&& other): + v(other.has_value() ? std::forward(*other) : std::forward(other.error())) + {} + + template, class GF = const G&, std::enable_if_t< + (std::is_convertible_v && std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && + std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> + + constexpr expected(const expected& other): + v(other.has_value() ? std::forward(*other) : std::forward(other.error())) + {} + + template && std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && + std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> + + constexpr expected(expected&& other): + v(other.has_value() ? std::forward(*other) : std::forward(other.error())) + {} + + + /* + * (6) + */ + + template && + !std::is_same_v, void> && + !std::is_same_v, std::in_place_t> && + !std::is_same_v> && + std::is_constructible_v && + !std::is_same_v, unexpected> && + !std::is_same_v, expected>, bool> = true> + constexpr explicit expected(U&& v): v(T(std::forward(v))) + {} + + template && + !std::is_same_v, void> && + !std::is_same_v, std::in_place_t> && + !std::is_same_v> && + std::is_constructible_v && + !std::is_same_v, unexpected> && + !std::is_same_v, expected>, bool> = true> + constexpr expected(U&& v): v(T(std::forward(v))) + {} + + /* + * (7) + */ + + template>, std::enable_if_t< + !std::is_convertible_v && std::is_constructible_v, bool> = true> + constexpr explicit expected(const unexpected& e): v(std::forward(e.error())) + {} + + template>, std::enable_if_t< + std::is_convertible_v && std::is_constructible_v, bool> = true> + constexpr expected(const unexpected& e): v(std::forward(e.error())) + {} + + /* + * (8) + */ + + template>, std::enable_if_t< + !std::is_convertible_v && std::is_constructible_v, bool> = true> + constexpr explicit expected(unexpected&& e): v(std::forward(e.error())) + {} + + template>, std::enable_if_t< + std::is_convertible_v && std::is_constructible_v, bool> = true> + constexpr expected(unexpected&& e): v(std::forward(e.error())) + {} + + /* + * (9)...(13) + */ + template, bool> = true> + constexpr explicit expected(std::in_place_t, Args&& ... args): v(T(std::forward(args)...)) + {} + + template&, Args...>, bool> = true> + constexpr explicit expected(std::in_place_t, std::initializer_list il, Args&& ... args): v(T(il, std::forward(args)...)) + {} + +// template, void>, bool> = true> +// constexpr explicit expected(std::in_place_t) noexcept: v(T()) +// {} + + template, bool> = true> + constexpr explicit expected(unexpect_t, Args&& ... args): v(E(std::forward(args)...)) + {} + + template&, Args...>, bool> = true> + constexpr explicit expected(unexpect_t, std::initializer_list il, Args&& ... args): v(E(il, std::forward(args)...)) + {} + + expected& operator=(const expected& copy) = delete; + + expected& operator=(expected&& move) = default; + + [[nodiscard]] constexpr explicit operator bool() const noexcept + { + return std::holds_alternative(v); + } + + [[nodiscard]] constexpr inline bool has_value() const noexcept + { + return std::holds_alternative(v); + } + + constexpr T& value()& + { + if (*this) + return std::get(v); + else + throw bad_expected_access(std::as_const(error())); + } + + constexpr const T& value() const& + { + if (*this) + return std::get(v); + else + throw bad_expected_access(std::as_const(error())); + } + + constexpr T&& value()&& + { + if (*this) + return std::get(v); + else + throw bad_expected_access(std::move(error())); + } + + constexpr const T&& value() const&& + { + if (*this) + return std::get(v); + else + throw bad_expected_access(std::move(error())); + } + + constexpr const E& error() const& noexcept + { + return std::get(v); + } + + constexpr E& error()& noexcept + { + return std::get(v); + } + + constexpr const E&& error() const&& noexcept + { + return std::get(v); + } + + constexpr E&& error()&& noexcept + { + return std::get(v); + } + + template && std::is_copy_constructible_v, bool> = true> + constexpr T value_or(U&& default_value) const& + { + return bool(*this) ? **this : static_cast(std::forward(default_value)); + } + + template && std::is_move_constructible_v, bool> = true> + constexpr T value_or(U&& default_value)&& + { + return bool(*this) ? std::move(**this) : static_cast(std::forward(default_value)); + } + + constexpr inline const T* operator->() const noexcept + { + return &std::get(v); + } + + constexpr inline T* operator->() noexcept + { + return &std::get(v); + } + + constexpr inline const T& operator*() const& noexcept + { + return std::get(v); + } + + constexpr inline T& operator*()& noexcept + { + return std::get(v); + } + + constexpr inline const T&& operator*() const&& noexcept + { + return std::move(std::get(v)); + } + + constexpr inline T&& operator*()&& noexcept + { + return std::move(std::get(v)); + } + }; + + template + class expected : expected + { + public: + using expected::expected; + + constexpr expected(const expected& copy): expected::v(copy ? *copy : copy.error()) + {} + + expected& operator=(const expected& copy) = default; + }; +} + +#endif //BLT_EXPECTED_H diff --git a/include/blt/std/ranges.h b/include/blt/std/ranges.h new file mode 100644 index 0000000..bb29df4 --- /dev/null +++ b/include/blt/std/ranges.h @@ -0,0 +1,170 @@ +#pragma once +/* + * Created by Brett on 06/02/24. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_RANGES_H +#define BLT_RANGES_H + +#include +#include +#include + +namespace blt +{ + template + class enumerator + { + public: + class iterator + { + public: + using iterator_category = std::input_iterator_tag; + using value_type = typename TYPE_ITR::value_type; + using difference_type = typename TYPE_ITR::difference_type; + using pointer = typename TYPE_ITR::pointer; + using reference = typename TYPE_ITR::reference; + private: + blt::size_t index = 0; + TYPE_ITR current; + public: + explicit iterator(TYPE_ITR current): current(std::move(current)) + {} + + iterator& operator++() + { + ++index; + ++current; + return *this; + } + + bool operator==(iterator other) const + { + return current == other.current; + } + + bool operator!=(iterator other) const + { + return current != other.current; + } + + std::pair operator*() const + { + return {index, *current}; + }; + + std::pair operator*() + { + return {index, *current}; + }; + }; + + explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(std::move(begin)), end_(std::move(end)) + {} + + iterator begin() + { + return begin_; + } + + iterator end() + { + return end_; + } + + private: + iterator begin_; + iterator end_; + }; + + template + static inline auto enumerate(const T& container) + { + return enumerator{container.begin(), container.end()}; + } + + template + static inline auto enumerate(T& container) + { + return enumerator{container.begin(), container.end()}; + } + + template + struct range + { + public: + struct range_itr + { + public: + using iterator_category = std::bidirectional_iterator_tag; + using difference_type = T; + using value_type = T; + using pointer = T*; + using reference = T&; + private: + T current; + bool forward; + public: + + explicit range_itr(T current, bool forward): current(current), forward(forward) + {} + + value_type operator*() const + { return current; } + + value_type operator->() + { return current; } + + range_itr& operator++() + { + if (forward) + current++; + else + current--; + return *this; + } + + range_itr& operator--() + { + if (forward) + current--; + else + current++; + return *this; + } + + friend bool operator==(const range_itr& a, const range_itr& b) + { + return a.current == b.current; + } + + friend bool operator!=(const range_itr& a, const range_itr& b) + { + return a.current != b.current; + } + }; + + private: + T _begin; + T _end; + T offset = 0; + public: + range(T begin, T end): _begin(begin), _end(end), offset(end < begin ? 1 : 0) + {} + + range_itr begin() + { + return range_itr(_begin - offset, offset == 0); + } + + range_itr end() + { + // not sure if i like this + return range_itr(_end - offset, offset == 0); + } + }; +} + +#endif //BLT_RANGES_H diff --git a/include/blt/std/utility.h b/include/blt/std/utility.h index 4e9f951..edf4f8a 100644 --- a/include/blt/std/utility.h +++ b/include/blt/std/utility.h @@ -19,9 +19,10 @@ #ifndef BLT_UTILITY_H #define BLT_UTILITY_H -#include #include -#include +#include +#include +#include #include #if defined(__GNUC__) @@ -59,516 +60,6 @@ namespace blt { return demangle(typeid(T).name()); } - - template - class enumerator - { - public: - class iterator - { - public: - using iterator_category = std::input_iterator_tag; - using value_type = typename TYPE_ITR::value_type; - using difference_type = typename TYPE_ITR::difference_type; - using pointer = typename TYPE_ITR::pointer; - using reference = typename TYPE_ITR::reference; - private: - size_t index = 0; - TYPE_ITR current; - public: - explicit iterator(TYPE_ITR current): current(std::move(current)) - {} - - iterator& operator++() - { - ++index; - ++current; - return *this; - } - - bool operator==(iterator other) const - { - return current == other.current; - } - - bool operator!=(iterator other) const - { - return current != other.current; - } - - std::pair operator*() const - { - return {index, *current}; - }; - - std::pair operator*() - { - return {index, *current}; - }; - }; - - explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(std::move(begin)), end_(std::move(end)) - {} - - iterator begin() - { - return begin_; - } - - iterator end() - { - return end_; - } - - private: - iterator begin_; - iterator end_; - }; - - template - static inline auto enumerate(const T& container) - { - return enumerator{container.begin(), container.end()}; - } - - template - static inline auto enumerate(T& container) - { - return enumerator{container.begin(), container.end()}; - } - - template - struct range - { - public: - struct range_itr - { - public: - using iterator_category = std::bidirectional_iterator_tag; - using difference_type = T; - using value_type = T; - using pointer = T*; - using reference = T&; - private: - T current; - bool forward; - public: - - explicit range_itr(T current, bool forward): current(current), forward(forward) - {} - - value_type operator*() const - { return current; } - - value_type operator->() - { return current; } - - range_itr& operator++() - { - if (forward) - current++; - else - current--; - return *this; - } - - range_itr& operator--() - { - if (forward) - current--; - else - current++; - return *this; - } - - friend bool operator==(const range_itr& a, const range_itr& b) - { - return a.current == b.current; - } - - friend bool operator!=(const range_itr& a, const range_itr& b) - { - return a.current != b.current; - } - }; - - private: - T _begin; - T _end; - T offset = 0; - public: - range(T begin, T end): _begin(begin), _end(end), offset(end < begin ? 1 : 0) - {} - - range_itr begin() - { - return range_itr(_begin - offset, offset == 0); - } - - range_itr end() - { - // not sure if i like this - return range_itr(_end - offset, offset == 0); - } - }; - - struct unexpect_t - { - explicit unexpect_t() = default; - }; - - inline constexpr unexpect_t unexpect{}; - - template - using remove_cvref_t = std::remove_reference_t>; - - template - class unexpected - { - private: - E e; - public: - constexpr unexpected(const unexpected&) = default; - - constexpr unexpected(unexpected&&) = default; - - template, unexpected> && !std::is_same_v, std::in_place_t> && - std::is_constructible_v, bool> = true> - constexpr explicit unexpected(Err&& e): e(std::forward(e)) - {} - - template, bool> = true> - constexpr explicit unexpected(std::in_place_t, Args&& ... args): e(std::forward(args)...) - {} - - template&, Args...>, bool> = true> - constexpr explicit unexpected(std::in_place_t, std::initializer_list il, Args&& ... args): e(il, std::forward(args)...) - {} - - constexpr const E& error() const& noexcept - { - return e; - } - - constexpr E& error()& noexcept - { - return e; - } - - constexpr const E&& error() const&& noexcept - { - return e; - } - - constexpr E&& error()&& noexcept - { - return e; - } - - constexpr void swap(unexpected& other) noexcept(std::is_nothrow_swappable_v) - { - std::swap(error(), other.error()); - } - - template - inline friend constexpr bool operator==(const unexpected& x, const unexpected & y) - { - return x.error() == y.error(); - } - - friend constexpr void swap(unexpected& x, unexpected& y) noexcept(noexcept(x.swap(y))) - {} - }; - - template - unexpected(E) -> unexpected; - - template - class bad_expected_access : public std::exception - { - private: - E e; - public: - explicit bad_expected_access(E e): e(std::move(e)) - {} - - const E& error() const& noexcept - { return e; } - - E& error()& noexcept - { return e; } - - const E&& error() const&& noexcept - { return e; } - - E&& error()&& noexcept - { return e; } - - [[nodiscard]] const char* what() const noexcept override - { return "blt::expected does not contain a value!"; } - - }; - - template> - class expected - { - protected: - std::variant v; - - template - inline static constexpr bool eight_insanity_v = - std::is_constructible_v&> || std::is_constructible_v> || - std::is_constructible_v&> || std::is_constructible_v> || - std::is_convertible_v&, T> || std::is_convertible_v, T> || - std::is_convertible_v&, T> || std::is_convertible_v, T>; - - template - inline static constexpr bool four_insanity_v = - std::is_constructible_v, expected&> || std::is_constructible_v, expected> || - std::is_constructible_v, const expected&> || std::is_constructible_v, const expected>; - - public: - template, bool> = true> - constexpr expected() noexcept: v(T()) - {} - - constexpr expected(const expected& copy) = delete; - - constexpr expected(expected&& move) noexcept: v(move ? std::move(*move) : std::move(move.error())) - {} - - /* - * (4)...(5) - */ - template, class GF = const G&, std::enable_if_t< - (!std::is_convertible_v || !std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && - std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> - - constexpr explicit expected(const expected& other): - v(other.has_value() ? std::forward(*other) : std::forward(other.error())) - {} - - template || !std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && - std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> - - constexpr explicit expected(expected&& other): - v(other.has_value() ? std::forward(*other) : std::forward(other.error())) - {} - - template, class GF = const G&, std::enable_if_t< - (std::is_convertible_v && std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && - std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> - - constexpr expected(const expected& other): - v(other.has_value() ? std::forward(*other) : std::forward(other.error())) - {} - - template && std::is_convertible_v) && (std::is_constructible_v || std::is_void_v) && - std::is_constructible_v && !eight_insanity_v < U, G>&& !four_insanity_v, bool> = true> - - constexpr expected(expected&& other): - v(other.has_value() ? std::forward(*other) : std::forward(other.error())) - {} - - - /* - * (6) - */ - - template && - !std::is_same_v, void> && - !std::is_same_v, std::in_place_t> && - !std::is_same_v> && - std::is_constructible_v && - !std::is_same_v, unexpected> && - !std::is_same_v, expected>, bool> = true> - constexpr explicit expected(U&& v): v(T(std::forward(v))) - {} - - template && - !std::is_same_v, void> && - !std::is_same_v, std::in_place_t> && - !std::is_same_v> && - std::is_constructible_v && - !std::is_same_v, unexpected> && - !std::is_same_v, expected>, bool> = true> - constexpr expected(U&& v): v(T(std::forward(v))) - {} - - /* - * (7) - */ - - template>, std::enable_if_t< - !std::is_convertible_v && std::is_constructible_v, bool> = true> - constexpr explicit expected(const unexpected& e): v(std::forward(e.error())) - {} - - template>, std::enable_if_t< - std::is_convertible_v && std::is_constructible_v, bool> = true> - constexpr expected(const unexpected& e): v(std::forward(e.error())) - {} - - /* - * (8) - */ - - template>, std::enable_if_t< - !std::is_convertible_v && std::is_constructible_v, bool> = true> - constexpr explicit expected(unexpected&& e): v(std::forward(e.error())) - {} - - template>, std::enable_if_t< - std::is_convertible_v && std::is_constructible_v, bool> = true> - constexpr expected(unexpected&& e): v(std::forward(e.error())) - {} - - /* - * (9)...(13) - */ - template, bool> = true> - constexpr explicit expected(std::in_place_t, Args&& ... args): v(T(std::forward(args)...)) - {} - - template&, Args...>, bool> = true> - constexpr explicit expected(std::in_place_t, std::initializer_list il, Args&& ... args): v(T(il, std::forward(args)...)) - {} - -// template, void>, bool> = true> -// constexpr explicit expected(std::in_place_t) noexcept: v(T()) -// {} - - template, bool> = true> - constexpr explicit expected(unexpect_t, Args&& ... args): v(E(std::forward(args)...)) - {} - - template&, Args...>, bool> = true> - constexpr explicit expected(unexpect_t, std::initializer_list il, Args&& ... args): v(E(il, std::forward(args)...)) - {} - - expected& operator=(const expected& copy) = delete; - - expected& operator=(expected&& move) = default; - - [[nodiscard]] constexpr explicit operator bool() const noexcept - { - return std::holds_alternative(v); - } - - [[nodiscard]] constexpr inline bool has_value() const noexcept - { - return std::holds_alternative(v); - } - - constexpr T& value()& - { - if (*this) - return std::get(v); - else - throw bad_expected_access(std::as_const(error())); - } - - constexpr const T& value() const& - { - if (*this) - return std::get(v); - else - throw bad_expected_access(std::as_const(error())); - } - - constexpr T&& value()&& - { - if (*this) - return std::get(v); - else - throw bad_expected_access(std::move(error())); - } - - constexpr const T&& value() const&& - { - if (*this) - return std::get(v); - else - throw bad_expected_access(std::move(error())); - } - - constexpr const E& error() const& noexcept - { - return std::get(v); - } - - constexpr E& error()& noexcept - { - return std::get(v); - } - - constexpr const E&& error() const&& noexcept - { - return std::get(v); - } - - constexpr E&& error()&& noexcept - { - return std::get(v); - } - - template && std::is_copy_constructible_v, bool> = true> - constexpr T value_or(U&& default_value) const& - { - return bool(*this) ? **this : static_cast(std::forward(default_value)); - } - - template && std::is_move_constructible_v, bool> = true> - constexpr T value_or(U&& default_value)&& - { - return bool(*this) ? std::move(**this) : static_cast(std::forward(default_value)); - } - - constexpr inline const T* operator->() const noexcept - { - return &std::get(v); - } - - constexpr inline T* operator->() noexcept - { - return &std::get(v); - } - - constexpr inline const T& operator*() const& noexcept - { - return std::get(v); - } - - constexpr inline T& operator*()& noexcept - { - return std::get(v); - } - - constexpr inline const T&& operator*() const&& noexcept - { - return std::move(std::get(v)); - } - - constexpr inline T&& operator*()&& noexcept - { - return std::move(std::get(v)); - } - }; - - template - class expected : expected - { - public: - using expected::expected; - - constexpr expected(const expected& copy): expected::v(copy ? *copy : copy.error()) - {} - - expected& operator=(const expected& copy) = default; - }; //#define BLT_LAMBDA(type, var, code) [](const type& var) -> auto { return code; } //#define BLT_LAMBDA(var, code) [](var) -> auto { return code; } diff --git a/src/blt/std/filesystem.cpp b/src/blt/fs/filesystem.cpp similarity index 98% rename from src/blt/std/filesystem.cpp rename to src/blt/fs/filesystem.cpp index 1e61daa..1cc2ef4 100755 --- a/src/blt/std/filesystem.cpp +++ b/src/blt/fs/filesystem.cpp @@ -3,7 +3,7 @@ * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ -#include +#include #include #include "blt/std/logging.h" diff --git a/src/blt/nbt/nbt.cpp b/src/blt/fs/nbt.cpp similarity index 98% rename from src/blt/nbt/nbt.cpp rename to src/blt/fs/nbt.cpp index fb8d297..e127f11 100755 --- a/src/blt/nbt/nbt.cpp +++ b/src/blt/fs/nbt.cpp @@ -3,7 +3,7 @@ * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ -#include +#include #include #include diff --git a/src/blt/nbt/nbt_block.cpp b/src/blt/fs/nbt_block.cpp similarity index 85% rename from src/blt/nbt/nbt_block.cpp rename to src/blt/fs/nbt_block.cpp index 346a45d..4b23ec6 100755 --- a/src/blt/nbt/nbt_block.cpp +++ b/src/blt/fs/nbt_block.cpp @@ -3,7 +3,7 @@ * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ -#include +#include #include #include diff --git a/src/blt/parse/obj_loader.cpp b/src/blt/parse/obj_loader.cpp index 01f4f03..6d85842 100644 --- a/src/blt/parse/obj_loader.cpp +++ b/src/blt/parse/obj_loader.cpp @@ -19,7 +19,7 @@ #define BLT_DISABLE_DEBUG #include -#include +#include #include #include #include diff --git a/src/blt/std/loader.cpp b/src/blt/std/loader.cpp index 48086c4..c078630 100755 --- a/src/blt/std/loader.cpp +++ b/src/blt/std/loader.cpp @@ -3,7 +3,7 @@ * Licensed under GNU General Public License V3.0 * See LICENSE file for license detail */ -#include +#include #include std::vector blt::fs::getLinesFromFile(std::string_view path) diff --git a/src/blt/std/system.cpp b/src/blt/std/system.cpp index e987d5d..a251a6d 100755 --- a/src/blt/std/system.cpp +++ b/src/blt/std/system.cpp @@ -15,7 +15,7 @@ #ifndef WIN32 #include - #include + #include #include "blt/std/assert.h" inline long blt_get_page_size() @@ -50,7 +50,7 @@ blt::system::memory_info_t process_proc() auto data = blt::string::split(str, ' '); BLT_ASSERT(data.size() == 7 && "Something went wrong when parsing /proc/self/statm! Expected 7 values!"); - blt::system::memory_info_t mem {}; + blt::system::memory_info_t mem{}; mem.size = page_size * std::stoull(data[0]); mem.resident = page_size * std::stoull(data[1]); diff --git a/tests/src/nbt_tests.cpp b/tests/src/nbt_tests.cpp index cca0bc6..1dc9ba3 100755 --- a/tests/src/nbt_tests.cpp +++ b/tests/src/nbt_tests.cpp @@ -4,11 +4,11 @@ * See LICENSE file for license detail */ #include "nbt_tests.h" -#include +#include #include #include #include -#include +#include #include void blt::tests::nbtFSBlockRead(size_t buff_size, size_t arr_size, size_t num_array, unsigned char** arr)