diff --git a/src/cpputils/container/smart_ptr.h b/src/cpputils/container/smart_ptr.h index 33b9e1a..69fcdb4 100644 --- a/src/cpputils/container/smart_ptr.h +++ b/src/cpputils/container/smart_ptr.h @@ -1,8 +1,8 @@ #pragma once #include -#include "MetaProgramming.h" -#include "exception.h" +#include +#include namespace utl { @@ -12,26 +12,26 @@ namespace utl { private: template - using cop_is_base_of = std::is_base_of, utl::mp_clean_type>; + using cop_is_base_of = std::is_base_of, mp::clean_type>; template struct __impl_cop_is_value : - public utl::mp_true { }; + public mp::c_true { }; template struct __impl_cop_is_value : - public utl::mp_false { }; + public mp::c_false { }; template class F, class X> - struct __impl_cop_is_value, utl::mp_enable_if, F>>> : - public utl::mp_false { }; + struct __impl_cop_is_value, mp::enable_if, F>>> : + public mp::c_false { }; template struct __impl_cop_is_value, void> : - public utl::mp_false { }; + public mp::c_false { }; template - using cop_is_value = __impl_cop_is_value>; + using cop_is_value = __impl_cop_is_value>; struct op_deleter_noop { inline void operator()(T*) { } }; @@ -78,35 +78,35 @@ namespace utl return *this; } - template::value, int> = 0> + template::value, int> = 0> inline smart_ptr& reset(X& x) { _value.reset(new X(x)); return *this; } - template::value, int> = 0> + template::value, int> = 0> inline smart_ptr& reset(X&& x) { _value.reset(new X(std::move(x))); return *this; } - template::value, int> = 0> + template::value, int> = 0> inline smart_ptr& reset(const smart_ptr& other) { _value = other._value; return *this; } - template::value, int> = 0> + template::value, int> = 0> inline smart_ptr& reset(smart_ptr&& other) { _value = std::move(other._value); return *this; } - template::value, int> = 0> + template::value, int> = 0> inline smart_ptr& reset(std::reference_wrapper&& ref) { _value.reset(&ref.get(), op_deleter_noop()); @@ -127,32 +127,32 @@ namespace utl smart_ptr() { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(X& x) : _value(new X(x)) { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(X&& x) : _value(new X(std::move(x))) { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(X* x) : _value(x) { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(const smart_ptr& other) : _value(other._value) { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(smart_ptr&& other) : _value(std::move(other._value)) { } - template::value, int> = 0> + template::value, int> = 0> smart_ptr(std::reference_wrapper&& ref) : _value(&ref.get(), op_deleter_noop()) { } diff --git a/src/cpputils/logging/global.h b/src/cpputils/logging/global.h index 19e4a9d..2961b09 100644 --- a/src/cpputils/logging/global.h +++ b/src/cpputils/logging/global.h @@ -8,7 +8,7 @@ // (LogLevel: debug|info|warn|error), [T_sender], [Message, [Arguments]] #define log_global_message(level, ...) \ if (::utl::logging::is_enabled(::utl::logging::log_level::level)) \ - ::utl::logging::make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::log_message() + ::utl::logging::make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::message() namespace utl { namespace logging { diff --git a/src/cpputils/logging/logger.h b/src/cpputils/logging/logger.h index fe42e92..2515660 100644 --- a/src/cpputils/logging/logger.h +++ b/src/cpputils/logging/logger.h @@ -2,14 +2,14 @@ #include #include -#include +#include // () mandatory // [] optional // (logger), (LogLevel: debug|info|warn|error), [Sender], [Message, [Arguments]] #define log_message(logger, level, ...) \ if (logger.is_enabled(::utl::logging::log_level::level)) \ - logger.make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::log_message() + logger.make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::message() namespace utl { namespace logging { @@ -24,7 +24,7 @@ namespace logging { data_ptr_s _data; public: - inline void operator=(const log_message& msg) + inline void operator=(const message& msg) { _data->message += msg.str(); } inline helper(logger& logger, data_ptr_s data) : diff --git a/src/cpputils/logging/log_message.h b/src/cpputils/logging/message.h similarity index 59% rename from src/cpputils/logging/log_message.h rename to src/cpputils/logging/message.h index eba7dc5..24f02af 100644 --- a/src/cpputils/logging/log_message.h +++ b/src/cpputils/logging/message.h @@ -3,7 +3,7 @@ namespace utl { namespace logging { - struct log_message + struct message { private: std::ostringstream _msg; @@ -13,29 +13,29 @@ namespace logging { { return _msg.str(); } template - inline log_message& operator <<(const T& value) + inline message& operator <<(const T& value) { _msg << value; return *this; } - inline log_message& operator <<(std::ostream& (*callback)(std::ostream&)) + inline message& operator <<(std::ostream& (*callback)(std::ostream&)) { callback(_msg); return *this; } - log_message() : + message() : _msg() { } - log_message(const std::string& msg) : + message(const std::string& msg) : _msg(msg) { } private: - log_message(log_message&&) = delete; - log_message(const log_message&) = delete; + message(message&&) = delete; + message(const message&) = delete; }; } diff --git a/src/cpputils/misc/linq.h b/src/cpputils/misc/linq.h index aeeac84..67eaa14 100644 --- a/src/cpputils/misc/linq.h +++ b/src/cpputils/misc/linq.h @@ -150,22 +150,21 @@ namespace linq { struct lookup_range : public tag_range { using value_type = lookup::value_type; - - enum class State + using state_type = enum class state { - Initialize, - Iterating, - Finished, + initialize, + iterating, + finished, }; - values_type& values; - size_t current; - size_t end; - State state; + values_type& values; + size_t current; + size_t end; + state_type state; inline value_type& front() { - assert(state == State::Iterating); + assert(state == state_type::iterating); assert(current < end); return *values[current]; } @@ -174,15 +173,15 @@ namespace linq { { switch (state) { - case State::Iterating: + case state_type::iterating: { ++current; } - case State::Initialize: + case state_type::initialize: { auto hasElements = (current < end); - state = (hasElements ? State::Iterating : State::Finished); + state = (hasElements ? state_type::iterating : state_type::finished); return hasElements; } @@ -197,7 +196,7 @@ namespace linq { values (v), current (c), end (e), - state (State::Initialize) + state (state_type::initialize) { LINQ_CTOR(); } inline lookup_range(const lookup_range& other) : @@ -889,23 +888,22 @@ namespace linq { using value_type = T; using range_type = TRange; using this_type = default_if_empty_range; - - enum class State + using state_type = enum class state { - Init, - Iterate, - Empty, - Finish + init, + iterate, + empty, + finish, }; range_type range; value_type value; - State state; + state_type state; inline value_type& front() { - assert(state != State::Init && state != State::Finish); - return (state == State::Empty + assert(state != state_type::init && state != state_type::finish); + return (state == state_type::empty ? value : range.front()); } @@ -914,23 +912,23 @@ namespace linq { { switch(state) { - case State::Init: + case state_type::init: state = range.next() - ? State::Iterate - : State::Empty; + ? state_type::iterate + : state_type::empty; return true; - case State::Iterate: + case state_type::iterate: if (!range.next()) { - state = State::Finish; + state = state_type::finish; return false; } return true; - case State::Empty: - state = State::Finish; + case state_type::empty: + state = state_type::finish; /* fall through */ default: @@ -942,7 +940,7 @@ namespace linq { inline default_if_empty_range(R&& r, X&& t) : range(std::forward(r)), value(t), - state(State::Init) + state(state_type::init) { LINQ_CTOR(); } inline default_if_empty_range(const default_if_empty_range& other) : diff --git a/src/cpputils/mp/core/types.h b/src/cpputils/mp/core/types.h index f73c1f2..31bbda7 100644 --- a/src/cpputils/mp/core/types.h +++ b/src/cpputils/mp/core/types.h @@ -6,5 +6,12 @@ namespace mp { template using void_t = void; + template + struct list { }; + + template + struct inherit : T... + { }; + } } \ No newline at end of file diff --git a/test/container/nullable.cpp b/test/container/nullable.cpp index d75c434..b3a280c 100644 --- a/test/container/nullable.cpp +++ b/test/container/nullable.cpp @@ -1,15 +1,15 @@ #include #include -struct TestData +struct test_data { static int ctorCount; static int dtorCount; - TestData() + test_data() { ++ctorCount; } - ~TestData() + ~test_data() { ++dtorCount; } }; @@ -31,11 +31,11 @@ struct NonCopyableTestData using NullableInt = utl::nullable; using NullableIntRef = utl::nullable; using NullableString = utl::nullable; -using NullableTestData = utl::nullable; +using NullableTestData = utl::nullable; using NullableNonCopyableTestData = utl::nullable; -int TestData::ctorCount = 0; -int TestData::dtorCount = 0; +int test_data::ctorCount = 0; +int test_data::dtorCount = 0; using namespace ::utl; using namespace ::testing; @@ -111,12 +111,12 @@ TEST(NullableTest, hasValue_operatorBool) TEST(NullableTest, reset) { - NullableTestData n(TestData{}); + NullableTestData n(test_data{}); EXPECT_TRUE (n.has_value()); - int tmp = TestData::dtorCount; + int tmp = test_data::dtorCount; n.reset(); EXPECT_FALSE(n.has_value()); - EXPECT_EQ (tmp + 1, TestData::dtorCount); + EXPECT_EQ (tmp + 1, test_data::dtorCount); } TEST(NullableTest, value_functor) diff --git a/test/misc/linq.cpp b/test/misc/linq.cpp index c9b478f..8389f85 100644 --- a/test/misc/linq.cpp +++ b/test/misc/linq.cpp @@ -4,15 +4,15 @@ namespace linq_tests { - struct TestData + struct test_data { int value; - TestData() : + test_data() : value(0) { } - TestData(int v) : + test_data(int v) : value(v) { } }; @@ -187,9 +187,9 @@ TEST(LinqTest, where) TEST(LinqTest, select) { - std::vector data({ TestData(1), TestData(2), TestData(3) }); + std::vector data({ test_data(1), test_data(2), test_data(3) }); auto range = from_container(data) - >> select([](TestData& td)->int& { + >> select([](test_data& td)->int& { return td.value; }); ASSERT_TRUE (range.next()); @@ -256,9 +256,9 @@ TEST(LinqTest, order_by) TEST(LinqTest, distinct) { - std::vector data({ TestData(1), TestData(2), TestData(3), TestData(1), TestData(2), TestData(4) }); + std::vector data({ test_data(1), test_data(2), test_data(3), test_data(1), test_data(2), test_data(4) }); auto range = from_container(data) - >> distinct([](TestData& l, TestData& r){ + >> distinct([](test_data& l, test_data& r){ return l.value < r.value; }); ASSERT_TRUE (range.next()); @@ -866,11 +866,11 @@ TEST(LinqTest, moveable_objects) TEST(LinqTest, const_objects) { - const TestData data[] = { TestData(1) }; + const test_data data[] = { test_data(1) }; { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> first(); @@ -879,7 +879,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> first_or_default(); @@ -888,7 +888,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return std::move(d); }) >> last(); @@ -897,7 +897,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> last_or_default(); @@ -906,7 +906,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> single(); @@ -915,7 +915,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> single_or_default(); @@ -924,7 +924,7 @@ TEST(LinqTest, const_objects) { auto v = from_array(data) - >> select([](const TestData& d) { + >> select([](const test_data& d) { return d; }) >> to_list();