diff --git a/include/etl/fsm.h b/include/etl/fsm.h index 36130a47..05b5259f 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -27,7 +27,7 @@ SOFTWARE. ******************************************************************************/ #if 0 -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. #endif //*************************************************************************** @@ -49,24 +49,24 @@ SOFTWARE. //*************************************************************************** #ifndef ETL_FSM_INCLUDED -#define ETL_FSM_INCLUDED + #define ETL_FSM_INCLUDED -#include "platform.h" -#include "array.h" -#include "nullptr.h" -#include "error_handler.h" -#include "exception.h" -#include "user_type.h" -#include "message_router.h" -#include "integral_limits.h" -#include "largest.h" -#if ETL_USING_CPP11 - #include "tuple.h" -#endif + #include "platform.h" + #include "array.h" + #include "error_handler.h" + #include "exception.h" + #include "integral_limits.h" + #include "largest.h" + #include "message_router.h" + #include "nullptr.h" + #include "user_type.h" + #if ETL_USING_CPP11 + #include "tuple.h" + #endif -#include + #include -#include "private/minmax_push.h" + #include "private/minmax_push.h" namespace etl { @@ -74,26 +74,26 @@ namespace etl class hfsm; /// Allow alternative type for state id. -#if !defined(ETL_FSM_STATE_ID_TYPE) + #if !defined(ETL_FSM_STATE_ID_TYPE) typedef uint_least8_t fsm_state_id_t; -#else + #else typedef ETL_FSM_STATE_ID_TYPE fsm_state_id_t; -#endif + #endif // For internal FSM use. typedef typename etl::larger_type::type fsm_internal_id_t; -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above template class fsm_state; -#else + #else template class fsm_state; -#endif + #endif //*************************************************************************** /// Base exception class for FSM. @@ -166,6 +166,7 @@ namespace etl class fsm_not_started : public etl::fsm_exception { public: + fsm_not_started(string_type file_name_, numeric_type line_number_) : etl::fsm_exception(ETL_ERROR_TEXT("fsm:not started", ETL_FSM_FILE_ID"F"), file_name_, line_number_) { @@ -179,6 +180,7 @@ namespace etl class fsm_reentrant_transition_forbidden : public etl::fsm_exception { public: + fsm_reentrant_transition_forbidden(string_type file_name_, numeric_type line_number_) : etl::fsm_exception(ETL_ERROR_TEXT("fsm:reentrant calls to start/receive/etc. forbidden", ETL_FSM_FILE_ID"G"), file_name_, line_number_) { @@ -195,7 +197,7 @@ namespace etl // Pass this whenever no state change is desired. // The highest unsigned value of fsm_state_id_t. static ETL_CONSTANT fsm_state_id_t No_State_Change = etl::integral_limits::max; - + // Pass this when this event also needs to be passed to the parent. static ETL_CONSTANT fsm_state_id_t Pass_To_Parent = No_State_Change - 1U; @@ -213,15 +215,16 @@ namespace etl ETL_CONSTANT fsm_state_id_t ifsm_state_helper::Self_Transition; // Compile-time: TState::ID must equal its index in the type list (0..N-1) - template struct check_ids : etl::true_type + template + struct check_ids : etl::true_type { }; template struct check_ids - : etl::integral_constant::value> + : etl::integral_constant::value> { - }; + }; //*************************************************************************** /// RAII detection mechanism to catch reentrant calls to methods that might @@ -231,6 +234,7 @@ namespace etl class fsm_reentrancy_guard { public: + //******************************************* /// Constructor. /// Checks if another method has locked reentrancy. @@ -250,29 +254,30 @@ namespace etl { is_locked = false; } - + private: + // Reference to the flag signifying a lock on the state machine. bool& is_locked; - + // Copy & move semantics disabled since this is a guard. fsm_reentrancy_guard(fsm_reentrancy_guard const&) ETL_DELETE; - fsm_reentrancy_guard& operator= (fsm_reentrancy_guard const&) ETL_DELETE; -#if ETL_USING_CPP11 + fsm_reentrancy_guard& operator=(fsm_reentrancy_guard const&) ETL_DELETE; + #if ETL_USING_CPP11 fsm_reentrancy_guard(fsm_reentrancy_guard&&) ETL_DELETE; - fsm_reentrancy_guard& operator= (fsm_reentrancy_guard&&) ETL_DELETE; -#endif + fsm_reentrancy_guard& operator=(fsm_reentrancy_guard&&) ETL_DELETE; + #endif }; - } + } // namespace private_fsm class ifsm_state; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// A class to store FSM states. //*************************************************************************** template - class fsm_state_pack + class fsm_state_pack { public: @@ -294,18 +299,18 @@ namespace etl /// Gets a reference to the state. //********************************* template - TState& get() - { - return etl::get(storage); + TState& get() + { + return etl::get(storage); } //********************************* /// Gets a const reference to the state. //********************************* template - const TState& get() const - { - return etl::get(storage); + const TState& get() const + { + return etl::get(storage); } private: @@ -322,9 +327,9 @@ namespace etl etl::tuple storage{}; /// Pointers to the states. - etl::ifsm_state* states[sizeof...(TStates)]{ &etl::get(storage)... }; + etl::ifsm_state* states[sizeof...(TStates)]{&etl::get(storage)...}; }; -#endif + #endif //*************************************************************************** /// Interface class for FSM states. @@ -341,17 +346,17 @@ namespace etl using private_fsm::ifsm_state_helper<>::Pass_To_Parent; using private_fsm::ifsm_state_helper<>::Self_Transition; -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above template friend class fsm_state; -#else + #else template friend class etl::fsm_state; -#endif + #endif //******************************************* /// Gets the id for this state. @@ -383,7 +388,7 @@ namespace etl template void set_child_states(etl::ifsm_state** state_list, TSize size) { - p_active_child = ETL_NULLPTR; + p_active_child = ETL_NULLPTR; p_default_child = ETL_NULLPTR; for (TSize i = 0; i < size; ++i) @@ -399,11 +404,11 @@ namespace etl /// Constructor. //******************************************* ifsm_state(etl::fsm_state_id_t state_id_) - : state_id(state_id_), - p_context(ETL_NULLPTR), - p_parent(ETL_NULLPTR), - p_active_child(ETL_NULLPTR), - p_default_child(ETL_NULLPTR) + : state_id(state_id_) + , p_context(ETL_NULLPTR) + , p_parent(ETL_NULLPTR) + , p_active_child(ETL_NULLPTR) + , p_default_child(ETL_NULLPTR) { } @@ -424,8 +429,11 @@ namespace etl virtual fsm_state_id_t process_event(const etl::imessage& message) = 0; - virtual fsm_state_id_t on_enter_state() { return No_State_Change; } // By default, do nothing. - virtual void on_exit_state() {} // By default, do nothing. + virtual fsm_state_id_t on_enter_state() + { + return No_State_Change; + } // By default, do nothing. + virtual void on_exit_state() {} // By default, do nothing. //******************************************* void set_fsm_context(etl::fsm& context) @@ -450,7 +458,7 @@ namespace etl // Disabled. ifsm_state(const ifsm_state&) ETL_DELETE; - ifsm_state& operator =(const ifsm_state&) ETL_DELETE; + ifsm_state& operator=(const ifsm_state&) ETL_DELETE; }; //*************************************************************************** @@ -482,7 +490,7 @@ namespace etl template void set_states(etl::ifsm_state** p_states, TSize size) { - state_list = p_states; + state_list = p_states; number_of_states = etl::fsm_state_id_t(size); ETL_ASSERT(number_of_states > 0, ETL_ERROR(etl::fsm_state_list_exception)); @@ -496,7 +504,7 @@ namespace etl } } -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //******************************************* /// Set the states for the FSM /// From an etl::fsm_state_pack. @@ -504,7 +512,7 @@ namespace etl template void set_states(etl::fsm_state_pack& state_pack) { - state_list = state_pack.get_state_list(); + state_list = state_pack.get_state_list(); number_of_states = etl::fsm_state_id_t(state_pack.size()); for (etl::fsm_state_id_t i = 0; i < number_of_states; ++i) @@ -512,7 +520,7 @@ namespace etl state_list[i]->set_fsm_context(*this); } } -#endif + #endif //******************************************* /// Starts the FSM. @@ -533,11 +541,11 @@ namespace etl if (call_on_enter_state) { etl::fsm_state_id_t next_state_id; - etl::ifsm_state* p_last_state; + etl::ifsm_state* p_last_state; do { - p_last_state = p_state; + p_last_state = p_state; next_state_id = p_state->on_enter_state(); if (next_state_id != ifsm_state::No_State_Change) { @@ -560,7 +568,7 @@ namespace etl { etl::fsm_state_id_t next_state_id = p_state->process_event(message); - process_state_change(next_state_id); + process_state_change(next_state_id); } else { @@ -670,9 +678,7 @@ namespace etl //******************************************** bool have_changed_state(etl::fsm_state_id_t next_state_id) const { - return (next_state_id != p_state->get_state_id()) && - (next_state_id != ifsm_state::No_State_Change) && - (next_state_id != ifsm_state::Self_Transition); + return (next_state_id != p_state->get_state_id()) && (next_state_id != ifsm_state::No_State_Change) && (next_state_id != ifsm_state::Self_Transition); } //******************************************** @@ -691,7 +697,7 @@ namespace etl p_state->on_exit_state(); next_state_id = p_state->on_enter_state(); } - + if (have_changed_state(next_state_id)) { ETL_ASSERT_OR_RETURN_VALUE(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception), p_state->get_state_id()); @@ -715,16 +721,16 @@ namespace etl return p_state->get_state_id(); } - etl::ifsm_state* p_state; ///< A pointer to the current state. - etl::ifsm_state** state_list; ///< The list of added states. - etl::fsm_state_id_t number_of_states; ///< The number of states. - bool is_processing_state_change; ///< Whether a method call that could potentially trigger a state change is active + etl::ifsm_state* p_state; ///< A pointer to the current state. + etl::ifsm_state** state_list; ///< The list of added states. + etl::fsm_state_id_t number_of_states; ///< The number of states. + bool is_processing_state_change; ///< Whether a method call that could potentially trigger a state change is active }; //************************************************************************************************* // For C++17 and above. //************************************************************************************************* -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above //*************************************************************************** // The definition for all types. //*************************************************************************** @@ -756,7 +762,7 @@ namespace etl //******************************************** struct result_t { - bool was_handled; + bool was_handled; etl::fsm_state_id_t state_id; }; @@ -795,17 +801,17 @@ namespace etl template ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; -#else -//************************************************************************************************* -// For C++14 and below. -//************************************************************************************************* + #else + //************************************************************************************************* + // For C++14 and below. + //************************************************************************************************* //*************************************************************************** // The definition for all 16 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -834,7 +840,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -864,10 +870,10 @@ namespace etl //*************************************************************************** // Specialisation for 15 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -896,7 +902,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -925,10 +931,10 @@ namespace etl //*************************************************************************** // Specialisation for 14 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -957,7 +963,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -985,10 +991,10 @@ namespace etl //*************************************************************************** // Specialisation for 13 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1017,7 +1023,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1044,9 +1050,9 @@ namespace etl //*************************************************************************** // Specialisation for 12 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1075,7 +1081,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1101,9 +1107,9 @@ namespace etl //*************************************************************************** // Specialisation for 11 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1132,7 +1138,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1157,9 +1163,9 @@ namespace etl //*************************************************************************** // Specialisation for 10 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1188,7 +1194,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1212,9 +1218,9 @@ namespace etl //*************************************************************************** // Specialisation for 9 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1243,7 +1249,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1266,8 +1272,8 @@ namespace etl //*************************************************************************** // Specialisation for 8 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1296,7 +1302,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1318,8 +1324,8 @@ namespace etl //*************************************************************************** // Specialisation for 7 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1348,7 +1354,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1369,8 +1375,8 @@ namespace etl //*************************************************************************** // Specialisation for 6 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1399,7 +1405,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1419,8 +1425,8 @@ namespace etl //*************************************************************************** // Specialisation for 5 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1449,7 +1455,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1468,7 +1474,7 @@ namespace etl //*************************************************************************** // Specialisation for 4 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1497,7 +1503,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1515,7 +1521,7 @@ namespace etl //*************************************************************************** // Specialisation for 3 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1544,7 +1550,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1561,7 +1567,7 @@ namespace etl //*************************************************************************** // Specialisation for 2 message types. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1590,7 +1596,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1606,7 +1612,7 @@ namespace etl //*************************************************************************** // Specialisation for 1 message type. //*************************************************************************** - template class fsm_state : public ifsm_state { @@ -1635,7 +1641,7 @@ namespace etl etl::fsm_state_id_t process_event(const etl::imessage& message) { etl::fsm_state_id_t new_state_id; - etl::message_id_t event_id = message.get_message_id(); + etl::message_id_t event_id = message.get_message_id(); switch (event_id) { @@ -1672,6 +1678,7 @@ namespace etl { return static_cast(ifsm_state::get_fsm_context()); } + private: etl::fsm_state_id_t process_event(const etl::imessage& message) @@ -1680,15 +1687,15 @@ namespace etl } }; - template ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; -#endif -} + #endif +} // namespace etl -#include "private/minmax_pop.h" + #include "private/minmax_pop.h" #endif diff --git a/include/etl/generators/fsm_generator.h b/include/etl/generators/fsm_generator.h index 0887af6c..85d9a813 100644 --- a/include/etl/generators/fsm_generator.h +++ b/include/etl/generators/fsm_generator.h @@ -31,7 +31,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -61,24 +61,24 @@ cog.outl("//******************************************************************** //*************************************************************************** #ifndef ETL_FSM_INCLUDED -#define ETL_FSM_INCLUDED + #define ETL_FSM_INCLUDED -#include "platform.h" -#include "array.h" -#include "nullptr.h" -#include "error_handler.h" -#include "exception.h" -#include "user_type.h" -#include "message_router.h" -#include "integral_limits.h" -#include "largest.h" -#if ETL_USING_CPP11 - #include "tuple.h" -#endif + #include "platform.h" + #include "array.h" + #include "error_handler.h" + #include "exception.h" + #include "integral_limits.h" + #include "largest.h" + #include "message_router.h" + #include "nullptr.h" + #include "user_type.h" + #if ETL_USING_CPP11 + #include "tuple.h" + #endif -#include + #include -#include "private/minmax_push.h" + #include "private/minmax_push.h" namespace etl { @@ -86,33 +86,33 @@ namespace etl class hfsm; /// Allow alternative type for state id. -#if !defined(ETL_FSM_STATE_ID_TYPE) + #if !defined(ETL_FSM_STATE_ID_TYPE) typedef uint_least8_t fsm_state_id_t; -#else + #else typedef ETL_FSM_STATE_ID_TYPE fsm_state_id_t; -#endif + #endif // For internal FSM use. typedef typename etl::larger_type::type fsm_internal_id_t; -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above template class fsm_state; -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("template ") + cog.out(" ") + cog.outl(" typename>") cog.outl("class fsm_state;") ]]]*/ - /*[[[end]]]*/ -#endif + /*[[[end]]]*/ + #endif //*************************************************************************** /// Base exception class for FSM. @@ -185,6 +185,7 @@ namespace etl class fsm_not_started : public etl::fsm_exception { public: + fsm_not_started(string_type file_name_, numeric_type line_number_) : etl::fsm_exception(ETL_ERROR_TEXT("fsm:not started", ETL_FSM_FILE_ID"F"), file_name_, line_number_) { @@ -198,6 +199,7 @@ namespace etl class fsm_reentrant_transition_forbidden : public etl::fsm_exception { public: + fsm_reentrant_transition_forbidden(string_type file_name_, numeric_type line_number_) : etl::fsm_exception(ETL_ERROR_TEXT("fsm:reentrant calls to start/receive/etc. forbidden", ETL_FSM_FILE_ID"G"), file_name_, line_number_) { @@ -214,7 +216,7 @@ namespace etl // Pass this whenever no state change is desired. // The highest unsigned value of fsm_state_id_t. static ETL_CONSTANT fsm_state_id_t No_State_Change = etl::integral_limits::max; - + // Pass this when this event also needs to be passed to the parent. static ETL_CONSTANT fsm_state_id_t Pass_To_Parent = No_State_Change - 1U; @@ -232,15 +234,16 @@ namespace etl ETL_CONSTANT fsm_state_id_t ifsm_state_helper::Self_Transition; // Compile-time: TState::ID must equal its index in the type list (0..N-1) - template struct check_ids : etl::true_type + template + struct check_ids : etl::true_type { }; template struct check_ids - : etl::integral_constant::value> + : etl::integral_constant::value> { - }; + }; //*************************************************************************** /// RAII detection mechanism to catch reentrant calls to methods that might @@ -250,6 +253,7 @@ namespace etl class fsm_reentrancy_guard { public: + //******************************************* /// Constructor. /// Checks if another method has locked reentrancy. @@ -269,29 +273,30 @@ namespace etl { is_locked = false; } - + private: + // Reference to the flag signifying a lock on the state machine. bool& is_locked; - + // Copy & move semantics disabled since this is a guard. fsm_reentrancy_guard(fsm_reentrancy_guard const&) ETL_DELETE; - fsm_reentrancy_guard& operator= (fsm_reentrancy_guard const&) ETL_DELETE; -#if ETL_USING_CPP11 + fsm_reentrancy_guard& operator=(fsm_reentrancy_guard const&) ETL_DELETE; + #if ETL_USING_CPP11 fsm_reentrancy_guard(fsm_reentrancy_guard&&) ETL_DELETE; - fsm_reentrancy_guard& operator= (fsm_reentrancy_guard&&) ETL_DELETE; -#endif + fsm_reentrancy_guard& operator=(fsm_reentrancy_guard&&) ETL_DELETE; + #endif }; - } + } // namespace private_fsm class ifsm_state; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// A class to store FSM states. //*************************************************************************** template - class fsm_state_pack + class fsm_state_pack { public: @@ -313,18 +318,18 @@ namespace etl /// Gets a reference to the state. //********************************* template - TState& get() - { - return etl::get(storage); + TState& get() + { + return etl::get(storage); } //********************************* /// Gets a const reference to the state. //********************************* template - const TState& get() const - { - return etl::get(storage); + const TState& get() const + { + return etl::get(storage); } private: @@ -341,9 +346,9 @@ namespace etl etl::tuple storage{}; /// Pointers to the states. - etl::ifsm_state* states[sizeof...(TStates)]{ &etl::get(storage)... }; + etl::ifsm_state* states[sizeof...(TStates)]{&etl::get(storage)...}; }; -#endif + #endif //*************************************************************************** /// Interface class for FSM states. @@ -360,24 +365,24 @@ namespace etl using private_fsm::ifsm_state_helper<>::Pass_To_Parent; using private_fsm::ifsm_state_helper<>::Self_Transition; -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above template friend class fsm_state; -#else + #else /*[[[cog import cog cog.outl(" template ") + cog.out(" ") + cog.outl(" typename>") ]]]*/ /*[[[end]]]*/ friend class etl::fsm_state; -#endif + #endif //******************************************* /// Gets the id for this state. @@ -409,7 +414,7 @@ namespace etl template void set_child_states(etl::ifsm_state** state_list, TSize size) { - p_active_child = ETL_NULLPTR; + p_active_child = ETL_NULLPTR; p_default_child = ETL_NULLPTR; for (TSize i = 0; i < size; ++i) @@ -425,11 +430,11 @@ namespace etl /// Constructor. //******************************************* ifsm_state(etl::fsm_state_id_t state_id_) - : state_id(state_id_), - p_context(ETL_NULLPTR), - p_parent(ETL_NULLPTR), - p_active_child(ETL_NULLPTR), - p_default_child(ETL_NULLPTR) + : state_id(state_id_) + , p_context(ETL_NULLPTR) + , p_parent(ETL_NULLPTR) + , p_active_child(ETL_NULLPTR) + , p_default_child(ETL_NULLPTR) { } @@ -450,8 +455,11 @@ namespace etl virtual fsm_state_id_t process_event(const etl::imessage& message) = 0; - virtual fsm_state_id_t on_enter_state() { return No_State_Change; } // By default, do nothing. - virtual void on_exit_state() {} // By default, do nothing. + virtual fsm_state_id_t on_enter_state() + { + return No_State_Change; + } // By default, do nothing. + virtual void on_exit_state() {} // By default, do nothing. //******************************************* void set_fsm_context(etl::fsm& context) @@ -476,7 +484,7 @@ namespace etl // Disabled. ifsm_state(const ifsm_state&) ETL_DELETE; - ifsm_state& operator =(const ifsm_state&) ETL_DELETE; + ifsm_state& operator=(const ifsm_state&) ETL_DELETE; }; //*************************************************************************** @@ -508,7 +516,7 @@ namespace etl template void set_states(etl::ifsm_state** p_states, TSize size) { - state_list = p_states; + state_list = p_states; number_of_states = etl::fsm_state_id_t(size); ETL_ASSERT(number_of_states > 0, ETL_ERROR(etl::fsm_state_list_exception)); @@ -522,7 +530,7 @@ namespace etl } } -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //******************************************* /// Set the states for the FSM /// From an etl::fsm_state_pack. @@ -530,7 +538,7 @@ namespace etl template void set_states(etl::fsm_state_pack& state_pack) { - state_list = state_pack.get_state_list(); + state_list = state_pack.get_state_list(); number_of_states = etl::fsm_state_id_t(state_pack.size()); for (etl::fsm_state_id_t i = 0; i < number_of_states; ++i) @@ -538,7 +546,7 @@ namespace etl state_list[i]->set_fsm_context(*this); } } -#endif + #endif //******************************************* /// Starts the FSM. @@ -559,11 +567,11 @@ namespace etl if (call_on_enter_state) { etl::fsm_state_id_t next_state_id; - etl::ifsm_state* p_last_state; + etl::ifsm_state* p_last_state; do { - p_last_state = p_state; + p_last_state = p_state; next_state_id = p_state->on_enter_state(); if (next_state_id != ifsm_state::No_State_Change) { @@ -586,7 +594,7 @@ namespace etl { etl::fsm_state_id_t next_state_id = p_state->process_event(message); - process_state_change(next_state_id); + process_state_change(next_state_id); } else { @@ -696,9 +704,7 @@ namespace etl //******************************************** bool have_changed_state(etl::fsm_state_id_t next_state_id) const { - return (next_state_id != p_state->get_state_id()) && - (next_state_id != ifsm_state::No_State_Change) && - (next_state_id != ifsm_state::Self_Transition); + return (next_state_id != p_state->get_state_id()) && (next_state_id != ifsm_state::No_State_Change) && (next_state_id != ifsm_state::Self_Transition); } //******************************************** @@ -717,7 +723,7 @@ namespace etl p_state->on_exit_state(); next_state_id = p_state->on_enter_state(); } - + if (have_changed_state(next_state_id)) { ETL_ASSERT_OR_RETURN_VALUE(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception), p_state->get_state_id()); @@ -741,16 +747,16 @@ namespace etl return p_state->get_state_id(); } - etl::ifsm_state* p_state; ///< A pointer to the current state. - etl::ifsm_state** state_list; ///< The list of added states. - etl::fsm_state_id_t number_of_states; ///< The number of states. - bool is_processing_state_change; ///< Whether a method call that could potentially trigger a state change is active + etl::ifsm_state* p_state; ///< A pointer to the current state. + etl::ifsm_state** state_list; ///< The list of added states. + etl::fsm_state_id_t number_of_states; ///< The number of states. + bool is_processing_state_change; ///< Whether a method call that could potentially trigger a state change is active }; //************************************************************************************************* // For C++17 and above. //************************************************************************************************* -#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above + #if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION) // For C++17 and above //*************************************************************************** // The definition for all types. //*************************************************************************** @@ -782,7 +788,7 @@ namespace etl //******************************************** struct result_t { - bool was_handled; + bool was_handled; etl::fsm_state_id_t state_id; }; @@ -821,11 +827,11 @@ namespace etl template ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID; -#else -//************************************************************************************************* -// For C++14 and below. -//************************************************************************************************* - /*[[[cog + #else + //************************************************************************************************* + // For C++14 and below. + //************************************************************************************************* + /*[[[cog import cog ################################################ # The first definition for all of the events. @@ -833,14 +839,14 @@ namespace etl cog.outl("//***************************************************************************") cog.outl("// The definition for all %s message types." % Handlers) cog.outl("//***************************************************************************") - cog.outl("template " % Handlers) + cog.out(" ") + cog.outl(" typename T%s = void>" % Handlers) cog.outl("class fsm_state : public ifsm_state") cog.outl("{") cog.outl("public:") @@ -868,7 +874,7 @@ namespace etl cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)") cog.outl(" {") cog.outl(" etl::fsm_state_id_t new_state_id;") - cog.outl(" etl::message_id_t event_id = message.get_message_id();") + cog.outl(" etl::message_id_t event_id = message.get_message_id();") cog.outl("") cog.outl(" switch (event_id)") cog.outl(" {") @@ -896,14 +902,14 @@ namespace etl else: cog.outl("// Specialisation for %d message types." % n) cog.outl("//***************************************************************************") - cog.outl("template " % n) + cog.out(" ") + cog.outl(" typename T%d>" % n) cog.out("class fsm_state(ifsm_state::get_fsm_context());") cog.outl(" }") + cog.outl("") cog.outl("private:") cog.outl("") cog.outl(" etl::fsm_state_id_t process_event(const etl::imessage& message)") @@ -1002,23 +1009,23 @@ namespace etl cog.outl("};") cog.outl("") - cog.outl("template " % Handlers) + cog.out(" ") + cog.outl(" typename T%s>" % Handlers) cog.out("ETL_CONSTANT etl::fsm_state_id_t fsm_state::STATE_ID;" % Handlers) ]]]*/ - /*[[[end]]]*/ -#endif -} + /*[[[end]]]*/ + #endif +} // namespace etl -#include "private/minmax_pop.h" + #include "private/minmax_pop.h" #endif diff --git a/include/etl/generators/largest_generator.h b/include/etl/generators/largest_generator.h index ff31d050..bc28bdd3 100644 --- a/include/etl/generators/largest_generator.h +++ b/include/etl/generators/largest_generator.h @@ -33,7 +33,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -63,19 +63,19 @@ cog.outl("//******************************************************************** //*************************************************************************** #ifndef ETL_LARGEST_INCLUDED -#define ETL_LARGEST_INCLUDED + #define ETL_LARGEST_INCLUDED ///\defgroup largest largest ///\ingroup utilities -#include "platform.h" -#include "type_traits.h" -#include "smallest.h" -#include "static_assert.h" + #include "platform.h" + #include "smallest.h" + #include "static_assert.h" + #include "type_traits.h" namespace etl { -#if ETL_USING_CPP11 && !defined(ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP11 && !defined(ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** /// Template to determine the largest type and size. /// Defines 'value_type' which is the type of the largest parameter. @@ -94,10 +94,10 @@ namespace etl // Set 'type' to be the largest of the first parameter and any of the others. // This is recursive. - using type = typename etl::conditional<(etl::size_of::value > etl::size_of::value), // Boolean - T1, // TrueType - largest_other> // FalseType - ::type; // The largest type of the two. + using type = typename etl::conditional<(etl::size_of::value > etl::size_of::value), // Boolean + T1, // TrueType + largest_other> // FalseType + ::type; // The largest type of the two. // The size of the largest type. enum @@ -122,18 +122,18 @@ namespace etl }; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using largest_type_t = typename largest_type::type; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template constexpr size_t largest_type_v = largest_type::size; -#endif + #endif -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("/// Template to determine the largest type and size.") @@ -142,16 +142,16 @@ namespace etl cog.outl("/// Defines 'size' which is the size of the largest parameter.") cog.outl("///\\ingroup largest") cog.outl("//***************************************************************************") - cog.out("template " % int(NTypes)) + cog.out(" ") + cog.outl(" typename T%s = void>" % int(NTypes)) cog.outl("struct largest_type") cog.outl("{") - cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ") + cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter.") cog.out(" typedef typename largest_type<") for n in range(2, int(NTypes)): cog.out("T%s, " % n) @@ -163,9 +163,9 @@ namespace etl cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.") cog.outl(" // This is recursive.") cog.outl(" typedef typename etl::conditional<(sizeof(T1) > sizeof(largest_other)), // Boolean") - cog.outl(" T1, // TrueType") - cog.outl(" largest_other> // FalseType") - cog.outl(" ::type type; // The largest type of the two.") + cog.outl(" T1, // TrueType") + cog.outl(" largest_other> // FalseType") + cog.outl(" ::type type; // The largest type of the two.") cog.outl("") cog.outl(" // The size of the largest type.") cog.outl(" enum") @@ -178,13 +178,13 @@ namespace etl cog.outl("// Specialisation for one template parameter.") cog.outl("//***************************************************************************") cog.outl("template ") - cog.out("struct largest_type") + cog.out(" ") + cog.outl(" void>") cog.outl("{") cog.outl(" typedef T1 type;") cog.outl("") @@ -194,10 +194,10 @@ namespace etl cog.outl(" };") cog.outl("};") ]]]*/ - /*[[[end]]]*/ -#endif + /*[[[end]]]*/ + #endif -#if ETL_USING_CPP11 && !defined(ETL_LARGEST_ALIGNMENT_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP11 && !defined(ETL_LARGEST_ALIGNMENT_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** /// Template to determine the largest alignment. /// Defines value which is the largest alignment of all the parameters. @@ -212,9 +212,9 @@ namespace etl // Set 'type' to be the largest of the first parameter and any of the others. // This is recursive. using type = typename etl::conditional<(etl::alignment_of::value > etl::alignment_of::value), // Boolean - T1, // TrueType - largest_other> // FalseType - ::type; // The largest type of the two. + T1, // TrueType + largest_other> // FalseType + ::type; // The largest type of the two. // The largest alignment. enum @@ -237,13 +237,13 @@ namespace etl }; }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t largest_alignment_v = largest_alignment::value; -#endif + #endif -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("/// Template to determine the largest alignment.") @@ -251,16 +251,16 @@ namespace etl cog.outl("/// Defines value which is the largest alignment of all the parameters.") cog.outl("///\\ingroup largest") cog.outl("//***************************************************************************") - cog.out("template " % int(NTypes)) + cog.out(" ") + cog.outl(" typename T%s = void>" % int(NTypes)) cog.outl("struct largest_alignment") cog.outl("{") - cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter. ") + cog.outl(" // Define 'largest_other' as 'largest_type' with all but the first parameter.") cog.out(" typedef typename largest_alignment<") for n in range(2, int(NTypes)): cog.out("T%s, " % n) @@ -272,9 +272,9 @@ namespace etl cog.outl(" // Set 'type' to be the largest of the first parameter and any of the others.") cog.outl(" // This is recursive.") cog.outl(" typedef typename etl::conditional<(etl::alignment_of::value > etl::alignment_of::value), // Boolean") - cog.outl(" T1, // TrueType") - cog.outl(" largest_other> // FalseType") - cog.outl(" ::type type; // The largest type of the two.") + cog.outl(" T1, // TrueType") + cog.outl(" largest_other> // FalseType") + cog.outl(" ::type type; // The largest type of the two.") cog.outl("") cog.outl(" // The largest alignment.") cog.outl(" enum") @@ -287,13 +287,13 @@ namespace etl cog.outl("// Specialisation for one template parameter.") cog.outl("//***************************************************************************") cog.outl("template ") - cog.out("struct largest_alignment") + cog.out(" ") + cog.outl(" void>") cog.outl("{") cog.outl(" typedef T1 type;") cog.outl("") @@ -303,8 +303,8 @@ namespace etl cog.outl(" };") cog.outl("};") ]]]*/ - /*[[[end]]]*/ -#endif + /*[[[end]]]*/ + #endif //*************************************************************************** /// Defines a type that is as larger or larger than the specified type. @@ -319,10 +319,10 @@ namespace etl typedef typename etl::smallest_int_for_bits::type>::bits + 1>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using larger_int_type_t = typename larger_int_type::type; -#endif + #endif //*************************************************************************** /// Defines a type that is as larger or larger than the specified type. @@ -337,10 +337,10 @@ namespace etl typedef typename etl::smallest_uint_for_bits::type>::bits + 1>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using larger_uint_type_t = typename larger_uint_type::type; -#endif + #endif //*************************************************************************** /// Defines a type that is as larger or larger than the specified type. @@ -367,12 +367,12 @@ namespace etl typedef typename etl::smallest_int_for_bits::bits + 1>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using larger_type_t = typename larger_type::type; -#endif + #endif -#if ETL_USING_CPP11 && !defined(ETL_LARGEST_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP11 && !defined(ETL_LARGEST_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** /// Template to determine the largest type, size and alignment. /// Defines value which is the largest type, size and alignment of all the parameters. @@ -390,18 +390,18 @@ namespace etl }; }; -#if ETL_USING_CPP11 - template - using largest_t = typename largest::type; -#endif + #if ETL_USING_CPP11 + template + using largest_t = typename largest::type; + #endif -#if ETL_USING_CPP17 - template - inline constexpr size_t largest_size = largest::size; -#endif + #if ETL_USING_CPP17 + template + inline constexpr size_t largest_size = largest::size; + #endif -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("/// Template to determine the largest type, size and alignment.") @@ -409,13 +409,13 @@ namespace etl cog.outl("/// Defines value which is the largest type, size and alignment of all the parameters.") cog.outl("///\\ingroup largest") cog.outl("//***************************************************************************") - cog.out("template " % NTypes) + cog.out(" ") + cog.outl(" typename T%s = void>" % NTypes) cog.outl("struct largest") cog.outl("{") cog.out(" typedef typename etl::largest_type<") @@ -445,8 +445,8 @@ namespace etl cog.outl(" };") cog.outl("};") ]]]*/ - /*[[[end]]]*/ -#endif -} + /*[[[end]]]*/ + #endif +} // namespace etl #endif diff --git a/include/etl/generators/message_packet_generator.h b/include/etl/generators/message_packet_generator.h index 36430509..d6eed1be 100644 --- a/include/etl/generators/message_packet_generator.h +++ b/include/etl/generators/message_packet_generator.h @@ -31,7 +31,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -61,30 +61,29 @@ cog.outl("//******************************************************************** //*************************************************************************** #ifndef ETL_MESSAGE_PACKET_INCLUDED -#define ETL_MESSAGE_PACKET_INCLUDED + #define ETL_MESSAGE_PACKET_INCLUDED -#include "platform.h" + #include "platform.h" -#include "message.h" -#include "error_handler.h" -#include "static_assert.h" -#include "largest.h" -#include "alignment.h" -#include "utility.h" -#include "type_list.h" + #include "alignment.h" + #include "error_handler.h" + #include "largest.h" + #include "message.h" + #include "static_assert.h" + #include "type_list.h" + #include "utility.h" -#include + #include namespace etl { -#if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP17 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** // The definition for all message types. //*************************************************************************** template class message_packet { - private: template @@ -100,18 +99,18 @@ namespace etl using message_types = etl::type_list; - //******************************************** -#include "private/diagnostic_uninitialized_push.h" + //******************************************** + #include "private/diagnostic_uninitialized_push.h" constexpr message_packet() noexcept : valid(false) { } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" - //******************************************** - /// - //******************************************** -#include "private/diagnostic_uninitialized_push.h" + //******************************************** + /// + //******************************************** + #include "private/diagnostic_uninitialized_push.h" template || IsInMessageList, int>::type> explicit message_packet(T&& msg) : valid(true) @@ -139,7 +138,7 @@ namespace etl ETL_STATIC_ASSERT(IsInMessageList, "Message not in packet type list"); } } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" //********************************************** message_packet(const message_packet& other) @@ -152,7 +151,7 @@ namespace etl } } -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************** message_packet(message_packet&& other) { @@ -163,7 +162,7 @@ namespace etl add_new_message(etl::move(other.get())); } } -#endif + #endif //********************************************** void copy(const message_packet& other) @@ -187,9 +186,9 @@ namespace etl } } - //********************************************** -#include "private/diagnostic_uninitialized_push.h" - message_packet& operator =(const message_packet& rhs) + //********************************************** + #include "private/diagnostic_uninitialized_push.h" + message_packet& operator=(const message_packet& rhs) { delete_current_message(); valid = rhs.is_valid(); @@ -200,11 +199,11 @@ namespace etl return *this; } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" - //********************************************** -#include "private/diagnostic_uninitialized_push.h" - message_packet& operator =(message_packet&& rhs) + //********************************************** + #include "private/diagnostic_uninitialized_push.h" + message_packet& operator=(message_packet&& rhs) { delete_current_message(); valid = rhs.is_valid(); @@ -215,7 +214,7 @@ namespace etl return *this; } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" //******************************************** ~message_packet() @@ -263,7 +262,7 @@ namespace etl //********************************************** template static ETL_CONSTEXPR - typename etl::enable_if::value, bool>::type + typename etl::enable_if::value, bool>::type accepts() { return accepts(); @@ -271,7 +270,7 @@ namespace etl enum { - SIZE = etl::largest::size, + SIZE = etl::largest::size, ALIGNMENT = etl::largest::alignment }; @@ -291,24 +290,24 @@ namespace etl return Id1 == id2; } - //******************************************** -#include "private/diagnostic_uninitialized_push.h" + //******************************************** + #include "private/diagnostic_uninitialized_push.h" void delete_current_message() { if (valid) { etl::imessage* pmsg = static_cast(data); -#if ETL_HAS_VIRTUAL_MESSAGES + #if ETL_HAS_VIRTUAL_MESSAGES pmsg->~imessage(); -#else + #else delete_message(pmsg); -#endif + #endif } } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" -#if !ETL_HAS_VIRTUAL_MESSAGES + #if !ETL_HAS_VIRTUAL_MESSAGES //******************************************** void delete_message(etl::imessage* pmsg) { @@ -330,7 +329,7 @@ namespace etl return false; } } -#endif + #endif //******************************************** void add_new_message(const etl::imessage& msg) @@ -344,7 +343,7 @@ namespace etl (add_new_message_type(etl::move(msg)) || ...); } -#include "private/diagnostic_uninitialized_push.h" + #include "private/diagnostic_uninitialized_push.h" //******************************************** /// Only enabled for types that are in the typelist. //******************************************** @@ -355,9 +354,9 @@ namespace etl void* p = data; new (p) etl::remove_reference_t((etl::forward(msg))); } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" -#include "private/diagnostic_uninitialized_push.h" + #include "private/diagnostic_uninitialized_push.h" //******************************************** template bool add_new_message_type(const etl::imessage& msg) @@ -373,7 +372,7 @@ namespace etl return false; } } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" //******************************************** template @@ -392,7 +391,7 @@ namespace etl } typename etl::aligned_storage::type data; - bool valid; + bool valid; }; //*************************************************************************** @@ -416,24 +415,24 @@ namespace etl using message_types = etl::type_list<>; - //******************************************** -#include "private/diagnostic_uninitialized_push.h" + //******************************************** + #include "private/diagnostic_uninitialized_push.h" constexpr message_packet() noexcept { } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" //********************************************** message_packet(const message_packet& /*other*/) { } -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************** message_packet(message_packet&& /*other*/) { } -#endif + #endif //********************************************** void copy(const message_packet& /*other*/) @@ -445,21 +444,21 @@ namespace etl { } - //********************************************** -#include "private/diagnostic_uninitialized_push.h" - message_packet& operator =(const message_packet& /*rhs*/) + //********************************************** + #include "private/diagnostic_uninitialized_push.h" + message_packet& operator=(const message_packet& /*rhs*/) { return *this; } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" - //********************************************** -#include "private/diagnostic_uninitialized_push.h" - message_packet& operator =(message_packet&& /*rhs*/) + //********************************************** + #include "private/diagnostic_uninitialized_push.h" + message_packet& operator=(message_packet&& /*rhs*/) { return *this; } -#include "private/diagnostic_pop.h" + #include "private/diagnostic_pop.h" //******************************************** ~message_packet() @@ -502,7 +501,7 @@ namespace etl enum { - SIZE = 0, + SIZE = 0, ALIGNMENT = 1 }; }; @@ -521,7 +520,7 @@ namespace etl template using message_packet_from_type_list_t = typename message_packet_from_type_list::type; -#else + #else /*[[[cog import cog @@ -532,10 +531,11 @@ namespace etl for i in range(1, n + 1): cog.out(" T%d::ID == id" % i) if i < n: - cog.out(" ||") if i % 4 == 0: cog.outl("") - cog.out(" ") + cog.out(" ||") + else: + cog.out(" ||") cog.outl(";") ################################################ @@ -544,10 +544,11 @@ namespace etl for i in range(1, n + 1): cog.out(" T%d::ID == Id" % i) if i < n: - cog.out(" ||") if i % 4 == 0: cog.outl("") - cog.out(" ") + cog.out(" ||") + else: + cog.out(" ||") cog.outl(";") ################################################ @@ -556,10 +557,11 @@ namespace etl for i in range(1, n + 1): cog.out(" T%d::ID == TMessage::ID" % i) if i < n: - cog.out(" ||") if i % 4 == 0: cog.outl("") - cog.out(" ") + cog.out(" ||") + else: + cog.out(" ||") cog.outl(";") ################################################ @@ -568,9 +570,9 @@ namespace etl cog.out(" static const bool Enabled = (!etl::is_same::type, etl::message_packet<") for i in range(1, n): cog.out("T%d, " % i) - cog.outl("T%s> >::value &&" % n) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" etl::is_one_of::type,") + cog.outl("T%s> >::value" % n) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && etl::is_one_of::type, ") for i in range(1, n): cog.out("T%d, " % i) cog.outl("T%s>::value);" % n) @@ -583,9 +585,9 @@ namespace etl cog.out(" static constexpr bool Enabled = (!etl::is_same::type, etl::message_packet<") for i in range(1, n): cog.out("T%d, " % i) - cog.outl("T%s> >::value &&" % n) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" etl::is_one_of::type,") + cog.outl("T%s> >::value" % n) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && etl::is_one_of::type, ") for i in range(1, n): cog.out("T%d, " % i) cog.outl("T%s>::value);" % n) @@ -598,36 +600,36 @@ namespace etl cog.outl("//***************************************************************************") cog.outl("// The definition for all %s message types." % Handlers) cog.outl("//***************************************************************************") - cog.out("template <") - for n in range(1, int(Handlers)): - cog.out("typename T%s = void, " % n) + cog.out("template " % int(Handlers)) + cog.out(" ") + cog.outl(" typename T%s = void>" % int(Handlers)) cog.outl("class message_packet") cog.outl("{") cog.outl("public:") cog.outl("") - cog.outl("#if ETL_USING_CPP11") + cog.outl(" #if ETL_USING_CPP11") cog.out(" using message_types = etl::type_list<") for n in range(1, int(Handlers)): cog.out("T%s, " % n) cog.outl("T%s>;" % int(Handlers)) - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" ETL_CONSTEXPR message_packet() ETL_NOEXCEPT") cog.outl(" : valid(false)") cog.outl(" {") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" explicit message_packet(const etl::imessage& msg)") cog.outl(" {") cog.outl(" if (accepts(msg))") @@ -642,11 +644,11 @@ namespace etl cog.outl("") cog.outl(" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" explicit message_packet(etl::imessage&& msg)") cog.outl(" {") cog.outl(" if (accepts(msg))") @@ -661,49 +663,51 @@ namespace etl cog.outl("") cog.outl(" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.out(" template ::type, etl::message_packet<") for n in range(1, int(Handlers)): cog.out("T%s, " % n) - cog.outl("T%s> >::value &&" % int(Handlers)) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" !etl::is_one_of::type, ") + cog.outl("T%s> >::value" % int(Handlers)) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && !etl::is_one_of::type, ") for n in range(1, int(Handlers)): cog.out("T%s, " % n) - cog.outl("T%s>::value, int>::type>" % int(Handlers)) + cog.outl("T%s>::value," % int(Handlers)) + cog.outl(" int>::type>") cog.outl(" explicit message_packet(TMessage&& /*msg*/)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp11(int(Handlers)) cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#else") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #else") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" template ") cog.out(" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet<") for n in range(1, int(Handlers)): cog.out("T%s, " % n) - cog.outl("T%s> >::value &&" % int(Handlers)) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" !etl::is_one_of::type, ") + cog.outl("T%s> >::value" % int(Handlers)) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && !etl::is_one_of::type, ") for n in range(1, int(Handlers)): cog.out("T%s, " % n) - cog.outl("T%s>::value, int>::type = 0)" % int(Handlers)) + cog.outl("T%s>::value," % int(Handlers)) + cog.outl(" int>::type = 0)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp03(int(Handlers)) cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" message_packet(const message_packet& other)") cog.outl(" : valid(other.is_valid())") cog.outl(" {") @@ -712,11 +716,11 @@ namespace etl cog.outl(" add_new_message(other.get());") cog.outl(" }") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" message_packet(message_packet&& other)") cog.outl(" : valid(other.is_valid())") cog.outl(" {") @@ -725,12 +729,12 @@ namespace etl cog.outl(" add_new_message(etl::move(other.get()));") cog.outl(" }") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") - cog.outl(" message_packet& operator =(const message_packet& rhs)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" message_packet& operator=(const message_packet& rhs)") cog.outl(" {") cog.outl(" delete_current_message();") cog.outl(" valid = rhs.is_valid();") @@ -741,12 +745,12 @@ namespace etl cog.outl("") cog.outl(" return *this;") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") - cog.outl(" message_packet& operator =(message_packet&& rhs)") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" message_packet& operator=(message_packet&& rhs)") cog.outl(" {") cog.outl(" delete_current_message();") cog.outl(" valid = rhs.is_valid();") @@ -757,8 +761,8 @@ namespace etl cog.outl("") cog.outl(" return *this;") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") cog.outl(" //********************************************") cog.outl(" ~message_packet()") @@ -806,7 +810,7 @@ namespace etl cog.outl(" //**********************************************") cog.outl(" template ") cog.outl(" static ETL_CONSTEXPR") - cog.outl(" typename etl::enable_if::value, bool>::type") + cog.outl(" typename etl::enable_if::value, bool>::type") cog.outl(" accepts()") cog.outl(" {") generate_accepts_return_compile_time_TMessage(int(Handlers)) @@ -834,11 +838,11 @@ namespace etl cog.outl(" {") cog.outl(" etl::imessage* pmsg = static_cast(data);") cog.outl("") - cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") + cog.outl(" #if ETL_HAS_VIRTUAL_MESSAGES") cog.outl(" pmsg->~imessage();") - cog.outl("#else") + cog.outl(" #else") cog.outl(" delete_message(pmsg);") - cog.outl("#endif") + cog.outl(" #endif") cog.outl(" }") cog.outl(" }") cog.outl(" #include \"private/diagnostic_pop.h\"") @@ -859,7 +863,7 @@ namespace etl cog.outl(" void add_new_message(const etl::imessage& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") - cog.outl(" void* p = data;") + cog.outl(" void* p = data;") cog.outl("") cog.outl(" switch (id)") cog.outl(" {") @@ -869,12 +873,12 @@ namespace etl cog.outl(" }") cog.outl(" }") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") cog.outl(" //********************************************") cog.outl(" void add_new_message(etl::imessage&& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") - cog.outl(" void* p = data;") + cog.outl(" void* p = data;") cog.outl("") cog.outl(" switch (id)") cog.outl(" {") @@ -883,14 +887,14 @@ namespace etl cog.outl(" default: ETL_ASSERT_FAIL(ETL_ERROR(unhandled_message_exception)); break;") cog.outl(" }") cog.outl(" }") - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") cog.outl(" typename etl::aligned_storage::type data;") - cog.outl(" bool valid;") + cog.outl(" bool valid;") cog.outl("};") #################################### - # All of the other specialisations. + #All of the other specialisations. #################################### for n in range(int(Handlers) - 1, 0, -1): cog.outl("") @@ -900,13 +904,16 @@ namespace etl else: cog.outl("// Specialisation for %d message types." % n) cog.outl("//***************************************************************************") - cog.out("template <") - for t in range(1, n): - cog.out("typename T%s, " % t) - if t % 4 == 0: - cog.outl("") - cog.out(" ") - cog.outl("typename T%s>" % n) + if n == 1: + cog.outl("template ") + else: + cog.out("template " % n) cog.out("class message_packet<") for t in range(1, n + 1): cog.out("T%d, " % t) @@ -923,25 +930,25 @@ namespace etl cog.outl("public:") cog.outl("") - cog.out("#if ETL_USING_CPP11") + cog.out(" #if ETL_USING_CPP11") cog.outl("") cog.out(" using message_types = etl::type_list<") for t in range(1, int(n)): cog.out("T%s, " % t) cog.outl("T%s>;" % int(n)) - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" ETL_CONSTEXPR message_packet() ETL_NOEXCEPT") cog.outl(" : valid(false)") cog.outl(" {") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" explicit message_packet(const etl::imessage& msg)") cog.outl(" {") cog.outl(" if (accepts(msg))") @@ -956,11 +963,11 @@ namespace etl cog.outl("") cog.outl(" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" explicit message_packet(etl::imessage&& msg)") cog.outl(" {") cog.outl(" if (accepts(msg))") @@ -975,49 +982,51 @@ namespace etl cog.outl("") cog.outl(" ETL_ASSERT(valid, ETL_ERROR(unhandled_message_exception));") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION) && !defined(ETL_COMPILER_GREEN_HILLS)") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.out(" template ::type, etl::message_packet<") for t in range(1, n): cog.out("T%s, " % t) - cog.outl("T%s> >::value &&" % n) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" !etl::is_one_of::type, ") + cog.outl("T%s> >::value" % n) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && !etl::is_one_of::type, ") for t in range(1, n): cog.out("T%s, " % t) - cog.outl("T%s>::value, int>::type>" % n) + cog.outl("T%s>::value," % n) + cog.outl(" int>::type>") cog.outl(" explicit message_packet(TMessage&& /*msg*/)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp11(n) cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#else") - cog.outl(" //********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #else") + cog.outl(" //********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" template ") cog.out(" explicit message_packet(const TMessage& /*msg*/, typename etl::enable_if::type, etl::message_packet<") for t in range(1, n): cog.out("T%s, " % t) - cog.outl("T%s> >::value &&" % n) - cog.outl(" !etl::is_same::type, etl::imessage>::value &&") - cog.out(" !etl::is_one_of::type, ") + cog.outl("T%s> >::value" % n) + cog.outl(" && !etl::is_same::type, etl::imessage>::value") + cog.out(" && !etl::is_one_of::type, ") for t in range(1, n): cog.out("T%s, " % t) - cog.outl("T%s>::value, int>::type = 0)" % n) + cog.outl("T%s>::value," % n) + cog.outl(" int>::type = 0)") cog.outl(" : valid(true)") cog.outl(" {") generate_static_assert_cpp03(n) cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" message_packet(const message_packet& other)") cog.outl(" : valid(other.is_valid())") cog.outl(" {") @@ -1026,11 +1035,11 @@ namespace etl cog.outl(" add_new_message(other.get());") cog.outl(" }") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") cog.outl(" message_packet(message_packet&& other)") cog.outl(" : valid(other.is_valid())") cog.outl(" {") @@ -1039,12 +1048,12 @@ namespace etl cog.outl(" add_new_message(etl::move(other.get()));") cog.outl(" }") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") - cog.outl(" message_packet& operator =(const message_packet& rhs)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" message_packet& operator=(const message_packet& rhs)") cog.outl(" {") cog.outl(" delete_current_message();") cog.outl(" valid = rhs.is_valid();") @@ -1055,12 +1064,12 @@ namespace etl cog.outl("") cog.outl(" return *this;") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") + cog.outl(" #include \"private/diagnostic_pop.h\"") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") - cog.outl(" //**********************************************") - cog.outl("#include \"private/diagnostic_uninitialized_push.h\"") - cog.outl(" message_packet& operator =(message_packet&& rhs)") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" //**********************************************") + cog.outl(" #include \"private/diagnostic_uninitialized_push.h\"") + cog.outl(" message_packet& operator=(message_packet&& rhs)") cog.outl(" {") cog.outl(" delete_current_message();") cog.outl(" valid = rhs.is_valid();") @@ -1071,8 +1080,8 @@ namespace etl cog.outl("") cog.outl(" return *this;") cog.outl(" }") - cog.outl("#include \"private/diagnostic_pop.h\"") - cog.outl("#endif") + cog.outl(" #include \"private/diagnostic_pop.h\"") + cog.outl(" #endif") cog.outl("") cog.outl(" //********************************************") cog.outl(" ~message_packet()") @@ -1120,7 +1129,7 @@ namespace etl cog.outl(" //**********************************************") cog.outl(" template ") cog.outl(" static ETL_CONSTEXPR") - cog.outl(" typename etl::enable_if::value, bool>::type") + cog.outl(" typename etl::enable_if::value, bool>::type") cog.outl(" accepts()") cog.outl(" {") generate_accepts_return_compile_time_TMessage(n) @@ -1148,12 +1157,11 @@ namespace etl cog.outl(" {") cog.outl(" etl::imessage* pmsg = static_cast(data);") cog.outl("") - cog.outl("") - cog.outl("#if ETL_HAS_VIRTUAL_MESSAGES") + cog.outl(" #if ETL_HAS_VIRTUAL_MESSAGES") cog.outl(" pmsg->~imessage();") - cog.outl("#else") + cog.outl(" #else") cog.outl(" delete_message(pmsg);") - cog.outl("#endif") + cog.outl(" #endif") cog.outl(" }") cog.outl(" }") cog.outl(" #include \"private/diagnostic_pop.h\"") @@ -1174,7 +1182,7 @@ namespace etl cog.outl(" void add_new_message(const etl::imessage& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") - cog.outl(" void* p = data;") + cog.outl(" void* p = data;") cog.outl("") cog.outl(" switch (id)") cog.outl(" {") @@ -1184,12 +1192,12 @@ namespace etl cog.outl(" }") cog.outl(" }") cog.outl("") - cog.outl("#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") + cog.outl(" #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_PACKET_FORCE_CPP03_IMPLEMENTATION)") cog.outl(" //********************************************") cog.outl(" void add_new_message(etl::imessage&& msg)") cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") - cog.outl(" void* p = data;") + cog.outl(" void* p = data;") cog.outl("") cog.outl(" switch (id)") cog.outl(" {") @@ -1198,10 +1206,10 @@ namespace etl cog.outl(" default: break;") cog.outl(" }") cog.outl(" }") - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") cog.outl(" typename etl::aligned_storage::type data;") - cog.outl(" bool valid;") + cog.outl(" bool valid;") cog.outl("};") ]]]*/ /*[[[end]]]*/ @@ -1215,9 +1223,9 @@ namespace etl { public: -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 using message_types = etl::type_list<>; -#endif + #endif ETL_CONSTEXPR message_packet() ETL_NOEXCEPT : valid(false) @@ -1253,7 +1261,7 @@ namespace etl enum { - SIZE = 0U, + SIZE = 0U, ALIGNMENT = 1U }; @@ -1261,7 +1269,7 @@ namespace etl bool valid; }; -#endif -} + #endif +} // namespace etl #endif diff --git a/include/etl/generators/message_router_generator.h b/include/etl/generators/message_router_generator.h index eeec698f..8106be25 100644 --- a/include/etl/generators/message_router_generator.h +++ b/include/etl/generators/message_router_generator.h @@ -31,7 +31,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -61,25 +61,25 @@ cog.outl("//******************************************************************** //*************************************************************************** #ifndef ETL_MESSAGE_ROUTER_INCLUDED -#define ETL_MESSAGE_ROUTER_INCLUDED + #define ETL_MESSAGE_ROUTER_INCLUDED -#include "platform.h" -#include "message.h" -#include "shared_message.h" -#include "message_packet.h" -#include "message_types.h" -#include "alignment.h" -#include "error_handler.h" -#include "exception.h" -#include "largest.h" -#include "nullptr.h" -#include "placement_new.h" -#include "successor.h" -#include "type_traits.h" -#include "type_list.h" -#include "array.h" + #include "platform.h" + #include "alignment.h" + #include "array.h" + #include "error_handler.h" + #include "exception.h" + #include "largest.h" + #include "message.h" + #include "message_packet.h" + #include "message_types.h" + #include "nullptr.h" + #include "placement_new.h" + #include "shared_message.h" + #include "successor.h" + #include "type_list.h" + #include "type_traits.h" -#include + #include namespace etl { @@ -120,7 +120,8 @@ namespace etl template class traits { -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 + private: using message_id_sequence = etl::index_sequence; @@ -131,10 +132,10 @@ namespace etl using message_types = etl::type_list; using sorted_message_types = etl::type_list_sort_t; - static_assert(etl::type_list_is_unique::value, "All TMessageTypes must be unique"); + static_assert(etl::type_list_is_unique::value, "All TMessageTypes must be unique"); static_assert(etl::type_list_all_of::value, "All TMessageTypes must satisfy the condition etl::is_message_type"); - static_assert(etl::index_sequence_is_unique::value, "All message IDs must be unique"); -#endif + static_assert(etl::index_sequence_is_unique::value, "All message IDs must be unique"); + #endif }; //*************************************************************************** @@ -148,13 +149,13 @@ namespace etl { public: -#if ETL_USING_CPP11 - using message_packet = etl::message_packet<>; - using message_types = etl::type_list<>; + #if ETL_USING_CPP11 + using message_packet = etl::message_packet<>; + using message_types = etl::type_list<>; using sorted_message_types = etl::type_list<>; -#endif + #endif }; - } + } // namespace private_message_router //*************************************************************************** /// Forward declare null message router functionality. @@ -171,11 +172,11 @@ namespace etl public: virtual ~imessage_router() {} - virtual void receive(const etl::imessage&) = 0; + virtual void receive(const etl::imessage&) = 0; virtual bool accepts(etl::message_id_t) const = 0; - virtual bool is_null_router() const = 0; - virtual bool is_producer() const = 0; - virtual bool is_consumer() const = 0; + virtual bool is_null_router() const = 0; + virtual bool is_producer() const = 0; + virtual bool is_consumer() const = 0; //******************************************** virtual void receive(etl::message_router_id_t destination_router_id, const etl::imessage& message) @@ -240,16 +241,16 @@ namespace etl // Disabled. imessage_router(const imessage_router&); - imessage_router& operator =(const imessage_router&); + imessage_router& operator=(const imessage_router&); - etl::message_router_id_t message_router_id; + etl::message_router_id_t message_router_id; }; //*************************************************************************** /// This router can be used as a sink for messages or a 'null source' router. //*************************************************************************** class null_message_router : public imessage_router - , public private_message_router::traits<> + , public private_message_router::traits<> { public: @@ -328,7 +329,7 @@ namespace etl /// This router can be used as a producer-only of messages, such an interrupt routine. //*************************************************************************** class message_producer : public imessage_router - , public private_message_router::traits<> + , public private_message_router::traits<> { public: @@ -416,7 +417,7 @@ namespace etl //*************************************************************************** template static - typename etl::enable_if::value && etl::is_message::value, void>::type + typename etl::enable_if::value && etl::is_message::value, void>::type send_message(TRouter& destination, const TMessage& message) { @@ -428,7 +429,7 @@ namespace etl //*************************************************************************** template static - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type send_message(TRouter& destination, etl::shared_message message) { @@ -440,7 +441,7 @@ namespace etl //*************************************************************************** template static - typename etl::enable_if::value && etl::is_message::value, void>::type + typename etl::enable_if::value && etl::is_message::value, void>::type send_message(TRouter& destination, etl::message_router_id_t id, const TMessage& message) @@ -453,7 +454,7 @@ namespace etl //*************************************************************************** template static - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type send_message(TRouter& destination, etl::message_router_id_t id, etl::shared_message message) @@ -464,13 +465,13 @@ namespace etl //************************************************************************************************* // For C++11 and above. //************************************************************************************************* -#if ETL_USING_CPP11 && !defined(ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP11 && !defined(ETL_MESSAGE_ROUTER_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** // The definition for all message types. //*************************************************************************** template class message_router : public imessage_router - , public private_message_router::traits + , public private_message_router::traits { public: @@ -525,8 +526,8 @@ namespace etl //*********************************************** void receive(const etl::imessage& msg) ETL_OVERRIDE { - etl::message_id_t id = msg.get_message_id(); - size_t index = Number_Of_Messages; + etl::message_id_t id = msg.get_message_id(); + size_t index = Number_Of_Messages; // The IDs are sorted, so an ID less than the first is not handled by this router. if (id >= Message_Id_Start) @@ -548,9 +549,9 @@ namespace etl } else { -#include "etl/private/diagnostic_array_bounds_push.h" + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); -#include "etl/private/diagnostic_pop.h" + #include "etl/private/diagnostic_pop.h" } } } @@ -564,9 +565,9 @@ namespace etl template ::value, int>::type = 0> void receive(const TMessage& msg) { -#include "etl/private/diagnostic_array_bounds_push.h" + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive(msg); -#include "etl/private/diagnostic_pop.h" + #include "etl/private/diagnostic_pop.h" } //********************************************** @@ -575,8 +576,7 @@ namespace etl /// \param msg The message. /// Enabled if TMessage is a message type, but not in the message type list. //********************************************** - template ::value && - !etl::is_one_of::value, int>::type = 0> + template ::value && !etl::is_one_of::value, int>::type = 0> void receive(const TMessage& msg) { if (has_successor()) @@ -585,9 +585,9 @@ namespace etl } else { -#include "etl/private/diagnostic_array_bounds_push.h" + #include "etl/private/diagnostic_array_bounds_push.h" static_cast(this)->on_receive_unknown(msg); -#include "etl/private/diagnostic_pop.h" + #include "etl/private/diagnostic_pop.h" } } @@ -662,9 +662,7 @@ namespace etl template struct contiguous_impl - : etl::bool_constant<(etl::type_list_type_at_index_t::ID + 1U == - etl::type_list_type_at_index_t::ID) && - contiguous_impl::value> + : etl::bool_constant<(etl::type_list_type_at_index_t::ID + 1U == etl::type_list_type_at_index_t::ID) && contiguous_impl::value> { }; @@ -701,7 +699,7 @@ namespace etl template static constexpr message_dispatch_table_t make_message_dispatch_table(etl::index_sequence) { - return message_dispatch_table_t{ { get_message_handler()... } }; + return message_dispatch_table_t{{get_message_handler()...}}; } //********************************************** @@ -721,7 +719,7 @@ namespace etl template static constexpr message_id_table_t make_message_id_table(etl::index_sequence) { - return message_id_table_t{ { get_message_id_from_index()... } }; + return message_id_table_t{{get_message_id_from_index()...}}; } //********************************************** @@ -732,7 +730,7 @@ namespace etl //********************************************** static size_t get_dispatch_index_from_message_id(etl::message_id_t id) { - if ETL_IF_CONSTEXPR(Message_Ids_Are_Contiguous) + if ETL_IF_CONSTEXPR (Message_Ids_Are_Contiguous) { // The IDs are contiguous, so we can calculate the index directly. return static_cast(id - Message_Id_Start); @@ -786,7 +784,7 @@ namespace etl etl::message_router::make_message_id_table(etl::make_index_sequence::Number_Of_Messages>{}); }; -#if ETL_USING_CPP11 && !ETL_USING_CPP17 + #if ETL_USING_CPP11 && !ETL_USING_CPP17 template constexpr const typename etl::message_router::message_dispatch_table_t etl::message_router::message_dispatch_table; @@ -794,14 +792,14 @@ namespace etl template constexpr const typename etl::message_router::message_id_table_t etl::message_router::message_id_table; -#endif + #endif //*************************************************************************** // The definition of a message_router for zero message types. //*************************************************************************** template class message_router : public imessage_router - , public private_message_router::traits<> + , public private_message_router::traits<> { public: @@ -850,12 +848,12 @@ namespace etl //*********************************************** void receive(const etl::imessage& msg) ETL_OVERRIDE { -#include "etl/private/diagnostic_array_bounds_push.h" + #include "etl/private/diagnostic_array_bounds_push.h" if (has_successor()) { get_successor().receive(msg); } -#include "etl/private/diagnostic_pop.h" + #include "etl/private/diagnostic_pop.h" } //********************************************** @@ -912,7 +910,7 @@ namespace etl template using message_router_from_type_list_t = typename message_router_from_type_list::type; -#else + #else //************************************************************************************************* // For C++03/98. //************************************************************************************************* @@ -935,7 +933,7 @@ namespace etl cog.out(" ") cog.outl("typename T%s = void>" % int(Handlers)) cog.out("class message_router") - cog.outl(" : public imessage_router") + cog.outl(" : public imessage_router") cog.outl("{") cog.outl("public:") cog.outl("") @@ -945,12 +943,12 @@ namespace etl cog.outl("T%s> message_packet;" % int(Handlers)) cog.outl("") - cog.outl("#if ETL_USING_CPP11") + cog.outl(" #if ETL_USING_CPP11") cog.out(" using message_types = etl::type_list<") for n in range(1, int(Handlers)): cog.out("T%s, " % n) cog.outl("T%s>;" % int(Handlers)) - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") cog.outl(" //**********************************************") @@ -986,7 +984,7 @@ namespace etl cog.outl(" {") cog.outl(" const etl::message_id_t id = msg.get_message_id();") cog.outl("") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" switch (id)") cog.outl(" {") for n in range(1, int(Handlers) + 1): @@ -994,19 +992,19 @@ namespace etl cog.out(" static_cast(this)->on_receive(static_cast(msg));" % n) cog.outl(" break;") cog.outl(" default:") - cog.outl(" {") - cog.outl(" if (has_successor())") - cog.outl(" {") - cog.outl(" get_successor().receive(msg);") - cog.outl(" }") - cog.outl(" else") - cog.outl(" {") - cog.outl(" static_cast(this)->on_receive_unknown(msg);") - cog.outl(" }") - cog.outl(" break;") - cog.outl(" }") + cog.outl(" {") + cog.outl(" if (has_successor())") + cog.outl(" {") + cog.outl(" get_successor().receive(msg);") + cog.outl(" }") + cog.outl(" else") + cog.outl(" {") + cog.outl(" static_cast(this)->on_receive_unknown(msg);") + cog.outl(" }") + cog.outl(" break;") + cog.outl(" }") cog.outl(" }") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -1016,9 +1014,9 @@ namespace etl cog.outl("T%s>::value, void>::type" % int(Handlers)) cog.outl(" receive(const TMessage& msg)") cog.outl(" {") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive(msg);") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -1034,9 +1032,9 @@ namespace etl cog.outl(" }") cog.outl(" else") cog.outl(" {") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive_unknown(msg);") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -1047,24 +1045,20 @@ namespace etl cog.outl(" {") cog.outl(" switch (id)") cog.outl(" {") - cog.out(" ") for n in range(1, int(Handlers) + 1): - cog.out(" case T%d::ID:" % n) - if n % 8 == 0: - cog.outl("") - cog.out(" ") - cog.outl(" return true;") + cog.outl(" case T%d::ID:" % n) + cog.outl(" return true;") cog.outl(" default:") - cog.outl(" {") - cog.outl(" if (has_successor())") cog.outl(" {") - cog.outl(" return get_successor().accepts(id);") + cog.outl(" if (has_successor())") + cog.outl(" {") + cog.outl(" return get_successor().accepts(id);") + cog.outl(" }") + cog.outl(" else") + cog.outl(" {") + cog.outl(" return false;") + cog.outl(" }") cog.outl(" }") - cog.outl(" else") - cog.outl(" {") - cog.outl(" return false;") - cog.outl(" }") - cog.outl(" }") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -1120,22 +1114,22 @@ namespace etl cog.outl("") cog.out(" ") cog.outl("void>") - cog.outl(" : public imessage_router") + cog.outl(" : public imessage_router") cog.outl("{") cog.outl("public:") cog.outl("") cog.out(" typedef etl::message_packet<") for t in range(1, n): cog.out("T%s, " % t) - cog.outl(" T%s> message_packet;" % n) + cog.outl("T%s> message_packet;" % n) cog.outl("") - cog.outl("#if ETL_USING_CPP11") + cog.outl(" #if ETL_USING_CPP11") cog.out(" using message_types = etl::type_list<") for t in range(1, n): cog.out("T%s, " % t) cog.outl("T%s>;" % n) - cog.outl("#endif") + cog.outl(" #endif") cog.outl("") cog.outl(" //**********************************************") @@ -1171,7 +1165,7 @@ namespace etl cog.outl(" {") cog.outl(" const size_t id = msg.get_message_id();") cog.outl("") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" switch (id)") cog.outl(" {") for t in range(1, n + 1): @@ -1179,19 +1173,19 @@ namespace etl cog.out(" static_cast(this)->on_receive(static_cast(msg));" % t) cog.outl(" break;") cog.outl(" default:") - cog.outl(" {") - cog.outl(" if (has_successor())") - cog.outl(" {") - cog.outl(" get_successor().receive(msg);") - cog.outl(" }") - cog.outl(" else") - cog.outl(" {") - cog.outl(" static_cast(this)->on_receive_unknown(msg);") - cog.outl(" }") - cog.outl(" break;") - cog.outl(" }") + cog.outl(" {") + cog.outl(" if (has_successor())") + cog.outl(" {") + cog.outl(" get_successor().receive(msg);") + cog.outl(" }") + cog.outl(" else") + cog.outl(" {") + cog.outl(" static_cast(this)->on_receive_unknown(msg);") + cog.outl(" }") + cog.outl(" break;") + cog.outl(" }") cog.outl(" }") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -1201,9 +1195,9 @@ namespace etl cog.outl("T%s>::value, void>::type" % n) cog.outl(" receive(const TMessage& msg)") cog.outl(" {") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive(msg);") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl("") cog.outl(" template ") @@ -1219,13 +1213,12 @@ namespace etl cog.outl(" }") cog.outl(" else") cog.outl(" {") - cog.outl("#include \"etl/private/diagnostic_array_bounds_push.h\"") + cog.outl(" #include \"etl/private/diagnostic_array_bounds_push.h\"") cog.outl(" static_cast(this)->on_receive_unknown(msg);") - cog.outl("#include \"etl/private/diagnostic_pop.h\"") + cog.outl(" #include \"etl/private/diagnostic_pop.h\"") cog.outl(" }") cog.outl(" }") cog.outl("") - cog.outl("") cog.outl(" //**********************************************") cog.outl(" using imessage_router::accepts;") cog.outl("") @@ -1233,26 +1226,20 @@ namespace etl cog.outl(" {") cog.outl(" switch (id)") cog.outl(" {") - cog.out(" ") for t in range(1, n + 1): - cog.out(" case T%d::ID:" % t) - if t % 8 == 0: - cog.outl("") - if t != n: - cog.out(" ") - cog.outl("") + cog.outl(" case T%d::ID:" % t) cog.outl(" return true;") cog.outl(" default:") - cog.outl(" {") - cog.outl(" if (has_successor())") cog.outl(" {") - cog.outl(" return get_successor().accepts(id);") + cog.outl(" if (has_successor())") + cog.outl(" {") + cog.outl(" return get_successor().accepts(id);") + cog.outl(" }") + cog.outl(" else") + cog.outl(" {") + cog.outl(" return false;") + cog.outl(" }") cog.outl(" }") - cog.outl(" else") - cog.outl(" {") - cog.outl(" return false;") - cog.outl(" }") - cog.outl(" }") cog.outl(" }") cog.outl(" }") cog.outl("") @@ -1288,9 +1275,9 @@ namespace etl typedef etl::message_packet<> message_packet; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 using message_types = etl::type_list<>; -#endif + #endif //********************************************** message_router(etl::message_router_id_t id_) @@ -1323,12 +1310,12 @@ namespace etl void receive(const etl::imessage& msg) ETL_OVERRIDE { -#include "etl/private/diagnostic_array_bounds_push.h" + #include "etl/private/diagnostic_array_bounds_push.h" if (has_successor()) { get_successor().receive(msg); } -#include "etl/private/diagnostic_pop.h" + #include "etl/private/diagnostic_pop.h" } //********************************************** @@ -1364,7 +1351,7 @@ namespace etl return true; } }; -#endif -} + #endif +} // namespace etl #endif diff --git a/include/etl/generators/smallest_generator.h b/include/etl/generators/smallest_generator.h index 1690119c..46e3ce2b 100644 --- a/include/etl/generators/smallest_generator.h +++ b/include/etl/generators/smallest_generator.h @@ -33,7 +33,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -63,19 +63,19 @@ cog.outl("//******************************************************************** //*************************************************************************** #ifndef ETL_SMALLEST_INCLUDED -#define ETL_SMALLEST_INCLUDED + #define ETL_SMALLEST_INCLUDED -#include "platform.h" -#include "integral_limits.h" + #include "platform.h" + #include "integral_limits.h" -#include + #include ///\defgroup smallest smallest ///\ingroup utilities namespace etl { -#if ETL_USING_CPP11 && !defined(ETL_SMALLEST_TYPE_FORCE_CPP03_IMPLEMENTATION) + #if ETL_USING_CPP11 && !defined(ETL_SMALLEST_TYPE_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** /// Template to determine the largest type and size. /// Defines 'value_type' which is the type of the largest parameter. @@ -95,9 +95,9 @@ namespace etl // Set 'type' to be the smallest of the first parameter and any of the others. // This is recursive. using type = typename etl::conditional<(etl::size_of::value < etl::size_of::value), // Boolean - T1, // TrueType - smallest_other> // FalseType - ::type; // The smallest type of the two. + T1, // TrueType + smallest_other> // FalseType + ::type; // The smallest type of the two. // The size of the smallest type. enum @@ -122,18 +122,18 @@ namespace etl }; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using smallest_type_t = typename smallest_type::type; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template constexpr size_t smallest_type_v = smallest_type::size; -#endif + #endif -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("/// Template to determine the smallest type and size.") @@ -142,13 +142,13 @@ namespace etl cog.outl("/// Defines 'size' which is the size of the smallest parameter.") cog.outl("///\\ingroup smallest") cog.outl("//***************************************************************************") - cog.out("template " % int(NTypes)) + cog.out(" ") + cog.outl(" typename T%s = void>" % int(NTypes)) cog.outl("struct smallest_type") cog.outl("{") cog.outl("private:") @@ -165,7 +165,7 @@ namespace etl cog.outl(" typedef TrueType type;") cog.outl(" };") cog.outl("") - cog.outl(" // Specialisation for 'false'. ") + cog.outl(" // Specialisation for 'false'.") cog.outl(" // Defines 'type' as 'FalseType'.") cog.outl(" template ") cog.outl(" struct choose_type") @@ -175,21 +175,21 @@ namespace etl cog.outl("") cog.outl("public:") cog.outl("") - cog.outl(" // Define 'smallest_other' as 'smallest_type' with all but the first parameter. ") - cog.out(" typedef typename smallest_type<") - for n in range(2, int(NTypes)): - cog.out("T%s, " % n) + cog.outl(" // Define 'smallest_other' as 'smallest_type' with all but the first parameter.") + cog.out(" typedef typename smallest_type::type smallest_other;" % int(NTypes)) + cog.outl(" T%s>::type smallest_other;" % int(NTypes)) cog.outl("") cog.outl(" // Set 'type' to be the smallest of the first parameter and any of the others.") cog.outl(" // This is recursive.") cog.outl(" typedef typename choose_type<(sizeof(T1) < sizeof(smallest_other)), // Boolean") - cog.outl(" T1, // TrueType") - cog.outl(" smallest_other> // FalseType") - cog.outl(" ::type type; // The smallest type of the two.") + cog.outl(" T1, // TrueType") + cog.outl(" smallest_other> // FalseType") + cog.outl(" ::type type; // The smallest type of the two.") cog.outl("") cog.outl(" // The size of the smallest type.") cog.outl(" enum") @@ -202,13 +202,13 @@ namespace etl cog.outl("// Specialisation for one template parameter.") cog.outl("//***************************************************************************") cog.outl("template ") - cog.out("struct smallest_type") + cog.out(" ") + cog.outl(" void>") cog.outl("{") cog.outl(" typedef T1 type;") cog.outl("") @@ -218,8 +218,8 @@ namespace etl cog.outl(" };") cog.outl("};") ]]]*/ - /*[[[end]]]*/ -#endif + /*[[[end]]]*/ + #endif namespace private_smallest { @@ -256,7 +256,7 @@ namespace etl typedef uint_least32_t type; }; -#if ETL_USING_64BIT_TYPES + #if ETL_USING_64BIT_TYPES //************************************************************************* // Greater than 32 bits. //************************************************************************* @@ -265,7 +265,7 @@ namespace etl { typedef uint_least64_t type; }; -#endif + #endif //************************************************************************* // Determine the type to hold the number of bits based on the index. @@ -300,7 +300,7 @@ namespace etl typedef int_least32_t type; }; -#if ETL_USING_64BIT_TYPES + #if ETL_USING_64BIT_TYPES //************************************************************************* // Greater than 32 bits. //************************************************************************* @@ -309,8 +309,8 @@ namespace etl { typedef int_least64_t type; }; -#endif - } + #endif + } // namespace private_smallest //*************************************************************************** /// Template to determine the smallest unsigned int type that can contain a @@ -324,9 +324,7 @@ namespace etl private: // Determines the index of the best unsigned type for the required number of bits. - static ETL_CONSTANT int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + - ((NBITS > 16) ? 1 : 0) + - ((NBITS > 32) ? 1 : 0); + static ETL_CONSTANT int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + ((NBITS > 16) ? 1 : 0) + ((NBITS > 32) ? 1 : 0); public: @@ -336,10 +334,10 @@ namespace etl template ETL_CONSTANT int smallest_uint_for_bits::TYPE_INDEX; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using smallest_uint_for_bits_t = typename smallest_uint_for_bits::type; -#endif + #endif //*************************************************************************** /// Template to determine the smallest signed int type that can contain a @@ -353,9 +351,7 @@ namespace etl private: // Determines the index of the best unsigned type for the required number of bits. - static ETL_CONSTANT int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + - ((NBITS > 16) ? 1 : 0) + - ((NBITS > 32) ? 1 : 0); + static ETL_CONSTANT int TYPE_INDEX = ((NBITS > 8) ? 1 : 0) + ((NBITS > 16) ? 1 : 0) + ((NBITS > 32) ? 1 : 0); public: @@ -365,10 +361,10 @@ namespace etl template ETL_CONSTANT int smallest_int_for_bits::TYPE_INDEX; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using smallest_int_for_bits_t = typename smallest_int_for_bits::type; -#endif + #endif //*************************************************************************** /// Template to determine the smallest unsigned int type that can contain the @@ -382,9 +378,7 @@ namespace etl private: // Determines the index of the best unsigned type for the required value. - static ETL_CONSTANT int TYPE_INDEX = ((VALUE > UINT_LEAST8_MAX) ? 1 : 0) + - ((VALUE > UINT16_MAX) ? 1 : 0) + - ((VALUE > UINT32_MAX) ? 1 : 0); + static ETL_CONSTANT int TYPE_INDEX = ((VALUE > UINT_LEAST8_MAX) ? 1 : 0) + ((VALUE > UINT16_MAX) ? 1 : 0) + ((VALUE > UINT32_MAX) ? 1 : 0); public: @@ -394,10 +388,10 @@ namespace etl template ETL_CONSTANT int smallest_uint_for_value::TYPE_INDEX; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using smallest_uint_for_value_t = typename smallest_uint_for_value::type; -#endif + #endif //*************************************************************************** /// Template to determine the smallest int type that can contain the @@ -411,9 +405,7 @@ namespace etl private: // Determines the index of the best signed type for the required value. - static ETL_CONSTANT int TYPE_INDEX = (((VALUE > intmax_t(INT_LEAST8_MAX)) || (VALUE < intmax_t(INT_LEAST8_MIN))) ? 1 : 0) + - (((VALUE > intmax_t(INT16_MAX)) || (VALUE < intmax_t(INT16_MIN))) ? 1 : 0) + - (((VALUE > intmax_t(INT32_MAX)) || (VALUE < intmax_t(INT32_MIN))) ? 1 : 0); + static ETL_CONSTANT int TYPE_INDEX = (((VALUE > intmax_t(INT_LEAST8_MAX)) || (VALUE < intmax_t(INT_LEAST8_MIN))) ? 1 : 0) + (((VALUE > intmax_t(INT16_MAX)) || (VALUE < intmax_t(INT16_MIN))) ? 1 : 0) + (((VALUE > intmax_t(INT32_MAX)) || (VALUE < intmax_t(INT32_MIN))) ? 1 : 0); public: @@ -423,10 +415,10 @@ namespace etl template ETL_CONSTANT int smallest_int_for_value::TYPE_INDEX; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using smallest_int_for_value_t = typename smallest_int_for_value::type; -#endif -} + #endif +} // namespace etl #endif diff --git a/include/etl/generators/type_lookup_generator.h b/include/etl/generators/type_lookup_generator.h index f1f2bb7e..43c56275 100644 --- a/include/etl/generators/type_lookup_generator.h +++ b/include/etl/generators/type_lookup_generator.h @@ -30,10 +30,10 @@ SOFTWARE. #define ETL_TYPE_LOOKUP_INCLUDED #include "platform.h" -#include "type_traits.h" -#include "static_assert.h" #include "integral_limits.h" #include "null_type.h" +#include "static_assert.h" +#include "type_traits.h" #include @@ -42,7 +42,7 @@ import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -85,7 +85,7 @@ namespace etl #if ETL_USING_CPP11 && !defined(ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION) //*************************************************************************** - // type_id_lookup + // type_id_lookup //*************************************************************************** template struct type_id_lookup @@ -93,7 +93,9 @@ namespace etl private: // The type for no match. - struct nulltype {}; + struct nulltype + { + }; // For N type pairs. template @@ -160,10 +162,10 @@ namespace etl static_assert(value != UNKNOWN, "Invalid type"); }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template static constexpr size_t id_from_type_v = id_from_type::value; -#endif + #endif //************************************ template @@ -171,7 +173,7 @@ namespace etl { return get_id_from_type(); } - + //************************************ template static unsigned int get_id_from_type() @@ -189,7 +191,9 @@ namespace etl private: // The type for no match. - struct nulltype {}; + struct nulltype + { + }; template struct type_from_type_helper @@ -227,14 +231,17 @@ namespace etl #else - /*[[[cog + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("// For %s types." % int(NTypes)) cog.outl("//***************************************************************************") + max_w = len(str(int(NTypes))) cog.outl("template , -%s>," %(n, n)) + pad = " " * (max_w - len(str(n))) + cog.outl(" typename T%s%s = etl::type_id_pair, -%s>," %(n, pad, n)) + cog.outl(" typename T%s = etl::type_id_pair, -%s> >" %(NTypes, NTypes)) cog.outl("struct type_id_lookup") cog.outl("{") @@ -244,7 +251,8 @@ namespace etl cog.outl(" template ") cog.outl(" struct type_from_id") cog.outl(" {") - cog.outl(" typedef ") + cog.outl(" // clang-format off") + cog.outl(" typedef") for n in range(1, int(NTypes) + 1): cog.outl(" typename etl::conditional >") @@ -257,6 +265,7 @@ namespace etl if n != int(NTypes): cog.outl("") cog.out(" ") + cog.outl(" // clang-format on") cog.outl("") cog.outl(" ETL_STATIC_ASSERT(!(etl::is_same, type>::value), \"Invalid id\");") cog.outl(" };") @@ -272,10 +281,12 @@ namespace etl cog.outl(" {") cog.outl(" enum") cog.outl(" {") - cog.outl(" value =") - for n in range(1, int(NTypes) + 1) : - cog.outl(" (unsigned int) etl::is_same::value ? (unsigned int)T%s::Id :" % (n, n)) - cog.outl(" (unsigned int) UNKNOWN") + first_pad = " " * (max_w - 1 + 3) + cog.outl(" value = (unsigned int)etl::is_same::value%s? (unsigned int)T1::Id" % first_pad) + for n in range(2, int(NTypes) + 1) : + pad = " " * (max_w - len(str(n)) + 1) + cog.outl(" : (unsigned int)etl::is_same::value%s? (unsigned int)T%s::Id" % (n, pad, n)) + cog.outl(" : (unsigned int)UNKNOWN") cog.outl(" };") cog.outl("") cog.outl(" ETL_STATIC_ASSERT(((unsigned int)value != (unsigned int)UNKNOWN), \"Invalid type\");") @@ -301,13 +312,15 @@ namespace etl cog.outl("//***************************************************************************") cog.outl("template , etl::null_type<0> >," %n) + pad = " " * (max_w - len(str(n))) + cog.outl(" typename T%s%s = etl::type_type_pair, etl::null_type<0> >," %(n, pad)) cog.outl(" typename T%s = etl::type_type_pair, etl::null_type<0> > >" %NTypes) cog.outl("struct type_type_lookup") cog.outl("{") cog.outl("public:") cog.outl("") cog.outl(" //************************************") + cog.outl(" // clang-format off") cog.outl(" template ") cog.outl(" struct type_from_type") cog.outl(" {") @@ -327,11 +340,12 @@ namespace etl cog.outl("") cog.outl(" ETL_STATIC_ASSERT(!(etl::is_same, type>::value), \"Invalid type\");") cog.outl(" };") + cog.outl(" // clang-format on") cog.outl("};") ]]]*/ - /*[[[end]]]*/ + /*[[[end]]]*/ #endif -} +} // namespace etl #endif diff --git a/include/etl/generators/type_select_generator.h b/include/etl/generators/type_select_generator.h index aab2d0f3..ff37fc28 100644 --- a/include/etl/generators/type_select_generator.h +++ b/include/etl/generators/type_select_generator.h @@ -30,16 +30,16 @@ SOFTWARE. #define ETL_TYPE_SELECT_INCLUDED #include "platform.h" +#include "null_type.h" #include "static_assert.h" #include "type_traits.h" -#include "null_type.h" /*[[[cog import cog cog.outl("#if 0") ]]]*/ /*[[[end]]]*/ -#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. + #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE. /*[[[cog import cog cog.outl("#endif") @@ -99,19 +99,22 @@ namespace etl // Select type alias //*************************************************************************** template - using type_select_t = typename etl::type_select:: template select_t; + using type_select_t = typename etl::type_select::template select_t; #else - /*[[[cog + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("// For %s types." % int(NTypes)) cog.outl("//***************************************************************************") + max_w = len(str(int(NTypes) - 1)) cog.outl("template " %(int(NTypes) - 1)) + pad = " " * (max_w - len(str(n))) + cog.outl(" typename T%s%s = void," % (n, pad)) + pad = " " * (max_w - len(str(int(NTypes) - 1))) + cog.outl(" typename T%s%s = void>" %(int(NTypes) - 1, pad)) cog.outl("struct type_select") cog.outl("{") cog.outl("public:") @@ -119,6 +122,7 @@ namespace etl cog.outl(" template ") cog.outl(" struct select") cog.outl(" {") + cog.outl(" // clang-format off") cog.outl(" typedef typename etl::conditional" % (s - 1)) cog.out("struct type_select<") @@ -151,9 +156,11 @@ namespace etl cog.outl("T%s>" % (s - 1)) cog.outl("{") cog.outl("public:") + cog.outl("") cog.outl(" template ") cog.outl(" struct select") cog.outl(" {") + cog.outl(" // clang-format off") cog.outl(" typedef typename etl::conditional -#include + #include + #include ///\defgroup type_traits type_traits /// A set of type traits definitions. /// Derived from either the standard or alternate definitions, dependent on whether or not ETL_NO_STL is defined. /// \ingroup utilities -#if ETL_USING_STL && ETL_USING_CPP11 - #include -#endif + #if ETL_USING_STL && ETL_USING_CPP11 + #include + #endif namespace etl { -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using void_t = void; -#endif + #endif -#if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED + #if ETL_NOT_USING_STL || ETL_CPP11_NOT_SUPPORTED //***************************************************************************** // Traits are defined by the ETL @@ -101,7 +101,7 @@ namespace etl { static const T value = VALUE; - typedef T value_type; + typedef T value_type; typedef integral_constant type; operator value_type() const @@ -117,23 +117,25 @@ namespace etl template const T integral_constant::value; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr T integral_constant_v = etl::integral_constant::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using bool_constant = integral_constant; -#else + #else template - struct bool_constant : etl::integral_constant { }; -#endif + struct bool_constant : etl::integral_constant + { + }; + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool bool_constant_v = bool_constant::value; -#endif + #endif //*************************************************************************** /// negation @@ -142,386 +144,749 @@ namespace etl { }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool negation_v = negation::value; -#endif + #endif //*************************************************************************** /// remove_reference - template struct remove_reference { typedef T type; }; - template struct remove_reference { typedef T type; }; -#if ETL_USING_CPP11 - template struct remove_reference { typedef T type; }; -#endif + template + struct remove_reference + { + typedef T type; + }; + template + struct remove_reference + { + typedef T type; + }; + #if ETL_USING_CPP11 + template + struct remove_reference + { + typedef T type; + }; + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_reference_t = typename remove_reference::type; -#endif + #endif //*************************************************************************** /// remove_pointer - template struct remove_pointer { typedef T type; }; - template struct remove_pointer { typedef T type; }; - template struct remove_pointer { typedef const T type; }; - template struct remove_pointer { typedef volatile T type; }; - template struct remove_pointer { typedef const volatile T type; }; - template struct remove_pointer { typedef T type; }; - template struct remove_pointer { typedef const T type; }; - template struct remove_pointer { typedef volatile T type; }; - template struct remove_pointer { typedef const volatile T type; }; + template + struct remove_pointer + { + typedef T type; + }; + template + struct remove_pointer + { + typedef T type; + }; + template + struct remove_pointer + { + typedef const T type; + }; + template + struct remove_pointer + { + typedef volatile T type; + }; + template + struct remove_pointer + { + typedef const volatile T type; + }; + template + struct remove_pointer + { + typedef T type; + }; + template + struct remove_pointer + { + typedef const T type; + }; + template + struct remove_pointer + { + typedef volatile T type; + }; + template + struct remove_pointer + { + typedef const volatile T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_pointer_t = typename remove_pointer::type; -#endif + #endif //*************************************************************************** /// add_pointer - template struct add_pointer { typedef typename remove_reference::type* type; }; + template + struct add_pointer + { + typedef typename remove_reference::type* type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_pointer_t = typename add_pointer::type; -#endif + #endif //*************************************************************************** /// is_const - template struct is_const : false_type {}; - template struct is_const : true_type {}; - template struct is_const : true_type {}; + template + struct is_const : false_type + { + }; + template + struct is_const : true_type + { + }; + template + struct is_const : true_type + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_const_v = is_const::value; -#endif + #endif //*************************************************************************** /// remove_const - template struct remove_const { typedef T type; }; - template struct remove_const { typedef T type; }; + template + struct remove_const + { + typedef T type; + }; + template + struct remove_const + { + typedef T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_const_t = typename remove_const::type; -#endif + #endif //*************************************************************************** /// add_const - template struct add_const { typedef const T type; }; - template struct add_const { typedef const T type; }; + template + struct add_const + { + typedef const T type; + }; + template + struct add_const + { + typedef const T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_const_t = typename add_const::type; -#endif + #endif //*************************************************************************** /// is_volatile - template struct is_volatile : false_type {}; - template struct is_volatile : true_type {}; - template struct is_volatile : true_type {}; + template + struct is_volatile : false_type + { + }; + template + struct is_volatile : true_type + { + }; + template + struct is_volatile : true_type + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_volatile_v = is_volatile::value; -#endif + #endif //*************************************************************************** /// remove_volatile - template struct remove_volatile { typedef T type; }; - template struct remove_volatile { typedef T type; }; + template + struct remove_volatile + { + typedef T type; + }; + template + struct remove_volatile + { + typedef T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_volatile_t = typename remove_volatile::type; -#endif + #endif //*************************************************************************** /// add_volatile - template struct add_volatile { typedef volatile T type; }; - template struct add_volatile { typedef volatile T type; }; + template + struct add_volatile + { + typedef volatile T type; + }; + template + struct add_volatile + { + typedef volatile T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_volatile_t = typename add_volatile::type; -#endif + #endif //*************************************************************************** /// remove_cv - template struct remove_cv + template + struct remove_cv { typedef typename remove_volatile::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_cv_t = typename remove_cv::type; -#endif + #endif //*************************************************************************** /// add_cv - template struct add_cv + template + struct add_cv { typedef typename add_volatile::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_cv_t = typename add_cv::type; -#endif + #endif //*************************************************************************** /// remove_cvref - template struct remove_cvref + template + struct remove_cvref { typedef typename remove_cv::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_cvref_t = typename remove_cvref::type; -#endif + #endif //*************************************************************************** /// is_integral - template struct is_integral : false_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; - template <> struct is_integral : true_type {}; -#if ETL_HAS_NATIVE_CHAR8_T - template <> struct is_integral : true_type {}; -#endif -#if ETL_HAS_NATIVE_CHAR16_T - template <> struct is_integral : true_type {}; -#endif -#if ETL_HAS_NATIVE_CHAR32_T - template <> struct is_integral : true_type {}; -#endif - template struct is_integral : is_integral {}; - template struct is_integral : is_integral {}; - template struct is_integral : is_integral {}; + template + struct is_integral : false_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + template <> + struct is_integral : true_type + { + }; + #if ETL_HAS_NATIVE_CHAR8_T + template <> + struct is_integral : true_type + { + }; + #endif + #if ETL_HAS_NATIVE_CHAR16_T + template <> + struct is_integral : true_type + { + }; + #endif + #if ETL_HAS_NATIVE_CHAR32_T + template <> + struct is_integral : true_type + { + }; + #endif + template + struct is_integral : is_integral + { + }; + template + struct is_integral : is_integral + { + }; + template + struct is_integral : is_integral + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_integral_v = is_integral::value; -#endif + #endif //*************************************************************************** /// is_signed - template struct is_signed : false_type {}; - template <> struct is_signed : etl::bool_constant<(char(255) < 0)> {}; - template <> struct is_signed : public etl::bool_constant {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; - template <> struct is_signed : true_type {}; -#if ETL_HAS_NATIVE_CHAR8_T - template <> struct is_signed : true_type {}; -#endif -#if ETL_HAS_NATIVE_CHAR16_T - template <> struct is_signed : true_type {}; -#endif -#if ETL_HAS_NATIVE_CHAR32_T - template <> struct is_signed : true_type {}; -#endif - template struct is_signed : is_signed {}; - template struct is_signed : is_signed {}; - template struct is_signed : is_signed {}; + template + struct is_signed : false_type + { + }; + template <> + struct is_signed : etl::bool_constant<(char(255) < 0)> + { + }; + template <> + struct is_signed : public etl::bool_constant + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + template <> + struct is_signed : true_type + { + }; + #if ETL_HAS_NATIVE_CHAR8_T + template <> + struct is_signed : true_type + { + }; + #endif + #if ETL_HAS_NATIVE_CHAR16_T + template <> + struct is_signed : true_type + { + }; + #endif + #if ETL_HAS_NATIVE_CHAR32_T + template <> + struct is_signed : true_type + { + }; + #endif + template + struct is_signed : is_signed + { + }; + template + struct is_signed : is_signed + { + }; + template + struct is_signed : is_signed + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_signed_v = is_signed::value; -#endif + #endif //*************************************************************************** /// is_unsigned - template struct is_unsigned : false_type {}; - template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : etl::bool_constant<(char(255) > 0)> {}; - template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : public etl::bool_constant<(wchar_t(-1) > wchar_t(0))> {}; - template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : true_type {}; - template struct is_unsigned : is_unsigned {}; - template struct is_unsigned : is_unsigned {}; - template struct is_unsigned : is_unsigned {}; + template + struct is_unsigned : false_type + { + }; + template <> + struct is_unsigned : true_type + { + }; + template <> + struct is_unsigned : etl::bool_constant<(char(255) > 0)> + { + }; + template <> + struct is_unsigned : true_type + { + }; + template <> + struct is_unsigned : public etl::bool_constant<(wchar_t(-1) > wchar_t(0))>{}; + template <> + struct is_unsigned : true_type + { + }; + template <> + struct is_unsigned : true_type + { + }; + template <> + struct is_unsigned : true_type + { + }; + template <> + struct is_unsigned : true_type + { + }; + template + struct is_unsigned : is_unsigned + { + }; + template + struct is_unsigned : is_unsigned + { + }; + template + struct is_unsigned : is_unsigned + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_unsigned_v = is_unsigned::value; -#endif + #endif //*************************************************************************** /// is_floating_point - template struct is_floating_point : false_type {}; - template <> struct is_floating_point : true_type {}; - template <> struct is_floating_point : true_type {}; - template <> struct is_floating_point : true_type {}; - template struct is_floating_point : is_floating_point {}; - template struct is_floating_point : is_floating_point {}; - template struct is_floating_point : is_floating_point {}; + template + struct is_floating_point : false_type + { + }; + template <> + struct is_floating_point : true_type + { + }; + template <> + struct is_floating_point : true_type + { + }; + template <> + struct is_floating_point : true_type + { + }; + template + struct is_floating_point : is_floating_point + { + }; + template + struct is_floating_point : is_floating_point + { + }; + template + struct is_floating_point : is_floating_point + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_floating_point_v = is_floating_point::value; -#endif + #endif //*************************************************************************** /// is_same - template struct is_same : public false_type {}; - template struct is_same : public true_type {}; + template + struct is_same : public false_type + { + }; + template + struct is_same : public true_type + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_same_v = is_same::value; -#endif + #endif //*************************************************************************** /// is_void - template struct is_void : false_type {}; - template<> struct is_void : true_type {}; + template + struct is_void : false_type + { + }; + template <> + struct is_void : true_type + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_void_v = is_void::value; -#endif + #endif //*************************************************************************** /// is_arithmetic - template struct is_arithmetic : etl::bool_constant::value || is_floating_point::value> {}; + template + struct is_arithmetic : etl::bool_constant::value || is_floating_point::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_arithmetic_v = is_arithmetic::value; -#endif + #endif //*************************************************************************** /// is_fundamental - template struct is_fundamental : etl::bool_constant::value || is_void::value> {}; + template + struct is_fundamental : etl::bool_constant::value || is_void::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_fundamental_v = is_fundamental::value; -#endif + #endif //*************************************************************************** /// is_compound - template struct is_compound : etl::bool_constant::value> {}; + template + struct is_compound : etl::bool_constant::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_compound_v = is_compound::value; -#endif + #endif //*************************************************************************** /// is_array - template struct is_array : false_type {}; - template struct is_array : true_type {}; - template struct is_array : true_type {}; + template + struct is_array : false_type + { + }; + template + struct is_array : true_type + { + }; + template + struct is_array : true_type + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_array_v = is_array::value; -#endif + #endif //*************************************************************************** /// is_pointer - template struct is_pointer_helper : false_type {}; - template struct is_pointer_helper : true_type {}; - template struct is_pointer_helper : is_pointer_helper {}; - template struct is_pointer_helper : is_pointer_helper {}; - template struct is_pointer_helper : is_pointer_helper {}; - template struct is_pointer : is_pointer_helper::type> {}; + template + struct is_pointer_helper : false_type + { + }; + template + struct is_pointer_helper : true_type + { + }; + template + struct is_pointer_helper : is_pointer_helper + { + }; + template + struct is_pointer_helper : is_pointer_helper + { + }; + template + struct is_pointer_helper : is_pointer_helper + { + }; + template + struct is_pointer : is_pointer_helper::type> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_pointer_v = is_pointer::value; -#endif + #endif //*************************************************************************** /// is_lvalue_reference - template struct is_lvalue_reference_helper : false_type {}; - template struct is_lvalue_reference_helper : true_type {}; - template struct is_lvalue_reference : is_lvalue_reference_helper::type> {}; + template + struct is_lvalue_reference_helper : false_type + { + }; + template + struct is_lvalue_reference_helper : true_type + { + }; + template + struct is_lvalue_reference : is_lvalue_reference_helper::type> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_lvalue_reference_v = etl::is_lvalue_reference::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// is_rvalue_reference - template struct is_rvalue_reference_helper : false_type {}; - template struct is_rvalue_reference_helper : true_type {}; - template struct is_rvalue_reference : is_rvalue_reference_helper::type> {}; + template + struct is_rvalue_reference_helper : false_type + { + }; + template + struct is_rvalue_reference_helper : true_type + { + }; + template + struct is_rvalue_reference : is_rvalue_reference_helper::type> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_rvalue_reference_v = etl::is_rvalue_reference::value; -#endif -#endif + #endif + #endif //*************************************************************************** /// is_reference // Either lvalue or rvalue (for CPP11) - template struct is_reference : integral_constant::value + template + struct is_reference : integral_constant::value #if ETL_USING_CPP11 - || is_rvalue_reference::value + || is_rvalue_reference::value #endif - >{}; + > + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_reference_v = is_reference::value; -#endif + #endif //*************************************************************************** /// is_pod /// Only fundamental and pointers types are recognised. - template struct is_pod : etl::bool_constant::value || etl::is_pointer::value> {}; + template + struct is_pod : etl::bool_constant::value || etl::is_pointer::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_pod_v = etl::is_pod::value; -#endif + #endif //*************************************************************************** /// conditional - template struct conditional { typedef T type; }; - template struct conditional { typedef F type; }; + template + struct conditional + { + typedef T type; + }; + template + struct conditional + { + typedef F type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using conditional_t = typename conditional::type; -#endif + #endif //*************************************************************************** /// make_signed - template struct make_signed { typedef T type; }; - template <> struct make_signed { typedef signed char type; }; - template <> struct make_signed { typedef signed char type; }; + template + struct make_signed + { + typedef T type; + }; + template <> + struct make_signed + { + typedef signed char type; + }; + template <> + struct make_signed + { + typedef signed char type; + }; - template <> struct make_signed + template <> + struct make_signed { typedef etl::conditional::type>::type type; }; - template <> struct make_signed { typedef short type; }; - template <> struct make_signed { typedef int type; }; - template <> struct make_signed { typedef long type; }; - template <> struct make_signed { typedef long long type; }; - template struct make_signed : add_const::type> {}; - template struct make_signed : add_volatile::type> {}; - template struct make_signed : add_const::type>::type> {}; + template <> + struct make_signed + { + typedef short type; + }; + template <> + struct make_signed + { + typedef int type; + }; + template <> + struct make_signed + { + typedef long type; + }; + template <> + struct make_signed + { + typedef long long type; + }; + template + struct make_signed : add_const::type> + { + }; + template + struct make_signed : add_volatile::type> + { + }; + template + struct make_signed : add_const::type>::type> + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using make_signed_t = typename make_signed::type; -#endif + #endif //*************************************************************************** /// make_unsigned - template struct make_unsigned { typedef T type; }; - template <> struct make_unsigned { typedef unsigned char type; }; - template <> struct make_unsigned { typedef unsigned char type; }; - template <> struct make_unsigned { typedef unsigned short type; }; + template + struct make_unsigned + { + typedef T type; + }; + template <> + struct make_unsigned + { + typedef unsigned char type; + }; + template <> + struct make_unsigned + { + typedef unsigned char type; + }; + template <> + struct make_unsigned + { + typedef unsigned short type; + }; - template <> struct make_unsigned + template <> + struct make_unsigned { typedef etl::conditional::type>::type type; }; - template <> struct make_unsigned { typedef unsigned int type; }; - template <> struct make_unsigned { typedef unsigned long type; }; - template <> struct make_unsigned { typedef unsigned long long type; }; - template struct make_unsigned : add_const::type> {}; - template struct make_unsigned : add_volatile::type> {}; - template struct make_unsigned : add_const::type>::type> {}; + template <> + struct make_unsigned + { + typedef unsigned int type; + }; + template <> + struct make_unsigned + { + typedef unsigned long type; + }; + template <> + struct make_unsigned + { + typedef unsigned long long type; + }; + template + struct make_unsigned : add_const::type> + { + }; + template + struct make_unsigned : add_volatile::type> + { + }; + template + struct make_unsigned : add_const::type>::type> + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using make_unsigned_t = typename make_unsigned::type; -#endif + #endif //*************************************************************************** /// enable_if - template struct enable_if {}; - template struct enable_if { typedef T type; }; + template + struct enable_if + { + }; + template + struct enable_if + { + typedef T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using enable_if_t = typename enable_if::type; -#endif + #endif //*************************************************************************** /// extent template - struct extent : integral_constant {}; + struct extent : integral_constant + { + }; template - struct extent : integral_constant {}; + struct extent : integral_constant + { + }; template - struct extent : integral_constant::value> {}; + struct extent : integral_constant::value> + { + }; template - struct extent : integral_constant {}; + struct extent : integral_constant + { + }; template - struct extent : integral_constant::value> {}; + struct extent : integral_constant::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t extent_v = extent::value; -#endif + #endif //*************************************************************************** /// remove_extent - template struct remove_extent { typedef T type; }; - template struct remove_extent { typedef T type; }; - template struct remove_extent { typedef T type; }; + template + struct remove_extent + { + typedef T type; + }; + template + struct remove_extent + { + typedef T type; + }; + template + struct remove_extent + { + typedef T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_extent_t = typename remove_extent::type; -#endif + #endif //*************************************************************************** /// remove_all_extents - template struct remove_all_extents { typedef T type; }; - template struct remove_all_extents { typedef typename remove_all_extents::type type; }; - template struct remove_all_extents { typedef typename remove_all_extents::type type; }; + template + struct remove_all_extents + { + typedef T type; + }; + template + struct remove_all_extents + { + typedef typename remove_all_extents::type type; + }; + template + struct remove_all_extents + { + typedef typename remove_all_extents::type type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_all_extents_t = typename remove_all_extents::type; -#endif + #endif //*************************************************************************** /// rank - template struct rank : integral_constant {}; - template struct rank : public integral_constant::value + 1> {}; - template struct rank : public integral_constant::value + 1> {}; + template + struct rank : integral_constant + { + }; + template + struct rank : public integral_constant::value + 1> + { + }; + template + struct rank : public integral_constant::value + 1> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t rank_v = rank::value; -#endif + #endif //*************************************************************************** /// decay template struct decay { - typedef typename etl::remove_reference::type U; + typedef typename etl::remove_reference::type U; typedef typename etl::conditional::value, typename etl::remove_extent::type*, typename etl::remove_cv::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using decay_t = typename decay::type; -#endif + #endif //*************************************************************************** /// is_class namespace private_type_traits { - template char test(int T::*); // Match for classes. + template + char test(int T::*); // Match for classes. - struct dummy { char c[2]; }; - template dummy test(...); // Match for non-classes. - } + struct dummy + { + char c[2]; + }; + template + dummy test(...); // Match for non-classes. + } // namespace private_type_traits template - struct is_class : etl::bool_constant(0)) == 1U> {}; + struct is_class : etl::bool_constant(0)) == 1U> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_class_v = is_class::value; -#endif + #endif - //*************************************************************************** - /// is_base_of -#if ETL_USING_CPP11 + //*************************************************************************** + /// is_base_of + #if ETL_USING_CPP11 namespace private_type_traits { - template + template etl::true_type test_ptr_conv(const volatile B*); - template + template etl::false_type test_ptr_conv(const volatile void*); - template + template auto test_is_base_of(int) -> decltype(test_ptr_conv(static_cast(nullptr))); - template + template auto test_is_base_of(...) -> etl::true_type; // private or ambiguous base - } + } // namespace private_type_traits - template - struct is_base_of: etl::integral_constant< - bool, - etl::is_class::value && - etl::is_class::value && - decltype(private_type_traits::test_is_base_of(0))::value - > {}; -#else - template::value || etl::is_fundamental::value || etl::is_array::value)> + template + struct is_base_of : etl::integral_constant< bool, etl::is_class::value && etl::is_class::value&& decltype(private_type_traits::test_is_base_of(0))::value > + { + }; + #else + template ::value || etl::is_fundamental::value || etl::is_array::value)> struct is_base_of { private: - static TBase* check(TBase*) { return (TBase*)0; } - static char check(...) { return 0; } + static TBase* check(TBase*) + { + return (TBase*)0; + } + static char check(...) + { + return 0; + } public: @@ -710,66 +1198,114 @@ namespace etl }; // For when TBase or TDerived is a fundamental type. - template + template struct is_base_of { static const bool value = false; }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_base_of_v = is_base_of::value; -#endif + #endif //*************************************************************************** /// add_lvalue_reference - template struct add_lvalue_reference { typedef T& type; }; - template struct add_lvalue_reference { typedef T& type; }; - template <> struct add_lvalue_reference { typedef void type; }; - template <> struct add_lvalue_reference { typedef const void type; }; - template <> struct add_lvalue_reference { typedef volatile void type; }; - template <> struct add_lvalue_reference { typedef const volatile void type; }; + template + struct add_lvalue_reference + { + typedef T& type; + }; + template + struct add_lvalue_reference + { + typedef T& type; + }; + template <> + struct add_lvalue_reference + { + typedef void type; + }; + template <> + struct add_lvalue_reference + { + typedef const void type; + }; + template <> + struct add_lvalue_reference + { + typedef volatile void type; + }; + template <> + struct add_lvalue_reference + { + typedef const volatile void type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_lvalue_reference_t = typename etl::add_lvalue_reference::type; -#endif + #endif - //*************************************************************************** - /// add_rvalue_reference -#if ETL_USING_CPP11 - template struct add_rvalue_reference { using type = T && ; }; - template struct add_rvalue_reference { using type = T & ; }; - template <> struct add_rvalue_reference { using type = void; }; - template <> struct add_rvalue_reference { using type = const void; }; - template <> struct add_rvalue_reference { using type = volatile void; }; - template <> struct add_rvalue_reference { using type = const volatile void; }; -#endif + //*************************************************************************** + /// add_rvalue_reference + #if ETL_USING_CPP11 + template + struct add_rvalue_reference + { + using type = T&&; + }; + template + struct add_rvalue_reference + { + using type = T&; + }; + template <> + struct add_rvalue_reference + { + using type = void; + }; + template <> + struct add_rvalue_reference + { + using type = const void; + }; + template <> + struct add_rvalue_reference + { + using type = volatile void; + }; + template <> + struct add_rvalue_reference + { + using type = const volatile void; + }; + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_rvalue_reference_t = typename etl::add_rvalue_reference::type; -#endif + #endif - //*************************************************************************** - /// declval -#if ETL_USING_CPP11 + //*************************************************************************** + /// declval + #if ETL_USING_CPP11 template typename etl::add_rvalue_reference::type declval() ETL_NOEXCEPT; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// is_enum ///\ingroup type_traits /// Implemented by checking if type is convertible to an integer through static_cast - namespace private_type_traits + namespace private_type_traits { // Base case template - struct is_convertible_to_int + struct is_convertible_to_int : false_type { }; @@ -778,86 +1314,82 @@ namespace etl // 2nd template argument of base case defaults to int to ensure that this partial specialization is always tried first template struct is_convertible_to_int(declval()))> - : true_type + : true_type { }; - } + } // namespace private_type_traits template struct is_enum - : integral_constant::value && - !is_class::value && - !is_arithmetic::value && - !is_reference::value> + : integral_constant::value && !is_class::value && !is_arithmetic::value && !is_reference::value> { }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_enum_v = etl::is_enum::value; -#endif -#else + #endif + #else namespace private_type_traits { // Helper to detect if a type is convertible to an integer template struct is_convertible_to_int { - static char test(int); // Match if T is convertible to int + static char test(int); // Match if T is convertible to int static double test(...); // Fallback for other types static const bool value = sizeof(test(static_cast(0))) == sizeof(char); }; - } + } // namespace private_type_traits // Implementation of is_enum template struct is_enum { - static const bool value = private_type_traits::is_convertible_to_int::value && - !is_class::value && - !is_arithmetic::value && - !is_reference::value; + static const bool value = private_type_traits::is_convertible_to_int::value && !is_class::value && !is_arithmetic::value && !is_reference::value; }; -#endif + #endif - //*************************************************************************** - /// is_convertible - ///\ingroup type_traits -#if ETL_USING_CPP11 + //*************************************************************************** + /// is_convertible + ///\ingroup type_traits + #if ETL_USING_CPP11 namespace private_type_traits { template using true_type_for = etl::true_type; template - auto returnable(int)->true_type_for; + auto returnable(int) -> true_type_for; template - auto returnable(...)->etl::false_type; + auto returnable(...) -> etl::false_type; template - auto nonvoid_convertible(int)->true_type_for()(etl::declval())) - >; + auto nonvoid_convertible(int) -> true_type_for()(etl::declval())) >; template - auto nonvoid_convertible(...)->etl::false_type; - } + auto nonvoid_convertible(...) -> etl::false_type; + } // namespace private_type_traits -#if defined(ETL_COMPILER_ARM5) + #if defined(ETL_COMPILER_ARM5) template - struct is_convertible : etl::bool_constant<__is_convertible_to(TFrom, TTo)> {}; -#else + struct is_convertible : etl::bool_constant<__is_convertible_to(TFrom, TTo)> + { + }; + #else template - struct is_convertible : etl::bool_constant<(decltype(private_type_traits::returnable(0))::value && - decltype(private_type_traits::nonvoid_convertible(0))::value) || - (etl::is_void::value && etl::is_void::value)> {}; -#endif + struct is_convertible : etl::bool_constant<(decltype(private_type_traits::returnable(0))::value && decltype(private_type_traits::nonvoid_convertible(0))::value) || (etl::is_void::value && etl::is_void::value)> + { + }; + #endif // Is convertible and the conversion is noexcept. template struct is_nothrow_convertible { private: + // Helper: a function taking TTo to require the conversion. static void sink(TTo) noexcept; @@ -870,515 +1402,659 @@ namespace etl static etl::false_type test(...); public: + static ETL_CONSTANT bool value = decltype(test(0))::value; }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = etl::is_convertible::value; template inline constexpr bool is_nothrow_convertible_v = etl::is_nothrow_convertible::value; -#endif + #endif - //*************************************************************************** - /// Alignment templates. - /// These require compiler specific intrinsics. -#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5) - template struct alignment_of : integral_constant { }; -#elif defined(ETL_COMPILER_MICROSOFT) - template struct alignment_of : integral_constant {}; -#elif defined(ETL_COMPILER_IAR) || defined(ETL_COMPILER_TI) - template struct alignment_of : integral_constant {}; -#else - template struct alignment_of : integral_constant {}; -#endif + //*************************************************************************** + /// Alignment templates. + /// These require compiler specific intrinsics. + #if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5) + template + struct alignment_of : integral_constant + { + }; + #elif defined(ETL_COMPILER_MICROSOFT) + template + struct alignment_of : integral_constant + { + }; + #elif defined(ETL_COMPILER_IAR) || defined(ETL_COMPILER_TI) + template + struct alignment_of : integral_constant + { + }; + #else + template + struct alignment_of : integral_constant + { + }; + #endif /// Specialisation of 'alignment_of' for 'void'. ///\ingroup type_traits - template <> struct alignment_of : integral_constant {}; - template <> struct alignment_of : integral_constant {}; + template <> + struct alignment_of : integral_constant + { + }; + template <> + struct alignment_of : integral_constant + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t alignment_of_v = etl::alignment_of::value; -#endif + #endif -#else // Condition = ETL_USING_STL && ETL_USING_CPP11 + #else // Condition = ETL_USING_STL && ETL_USING_CPP11 -//***************************************************************************** -// Traits are derived from the STL -//***************************************************************************** + //***************************************************************************** + // Traits are derived from the STL + //***************************************************************************** //*************************************************************************** /// integral_constant ///\ingroup type_traits template - struct integral_constant : std::integral_constant {}; + struct integral_constant : std::integral_constant + { + }; -/// integral_constant specialisations -///\ingroup type_traits -typedef integral_constant false_type; -typedef integral_constant true_type; + /// integral_constant specialisations + ///\ingroup type_traits + typedef integral_constant false_type; + typedef integral_constant true_type; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr T integral_constant_v = std::integral_constant::value; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template using bool_constant = std::bool_constant; -#else + #else template - struct bool_constant : std::integral_constant { }; -#endif + struct bool_constant : std::integral_constant + { + }; + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool bool_constant_v = bool_constant::value; -#endif + #endif - //*************************************************************************** - /// negation - ///\ingroup type_traits -#if ETL_USING_CPP17 + //*************************************************************************** + /// negation + ///\ingroup type_traits + #if ETL_USING_CPP17 template using negation = std::negation; -#else + #else template struct negation : etl::bool_constant { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool negation_v = std::negation_v; -#endif + #endif //*************************************************************************** /// remove_reference ///\ingroup type_traits - template struct remove_reference : std::remove_reference {}; + template + struct remove_reference : std::remove_reference + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_reference_t = typename std::remove_reference::type; -#endif + #endif //*************************************************************************** /// remove_pointer ///\ingroup type_traits - template struct remove_pointer : std::remove_pointer {}; + template + struct remove_pointer : std::remove_pointer + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_pointer_t = typename std::remove_pointer::type; -#endif + #endif //*************************************************************************** /// add_pointer ///\ingroup type_traits - template struct add_pointer : std::add_pointer {}; + template + struct add_pointer : std::add_pointer + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_pointer_t = typename std::add_pointer::type; -#endif + #endif //*************************************************************************** /// is_const ///\ingroup type_traits - template struct is_const : std::is_const {}; + template + struct is_const : std::is_const + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_const_v = std::is_const_v; -#endif + #endif //*************************************************************************** /// remove_const ///\ingroup type_traits - template struct remove_const : std::remove_const {}; + template + struct remove_const : std::remove_const + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_const_t = typename std::remove_const::type; -#endif + #endif //*************************************************************************** /// add_const ///\ingroup type_traits - template struct add_const : std::add_const {}; + template + struct add_const : std::add_const + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_const_t = typename std::add_const::type; -#endif + #endif //*************************************************************************** /// is_volatile ///\ingroup type_traits - template struct is_volatile : std::is_volatile {}; + template + struct is_volatile : std::is_volatile + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_volatile_v = std::is_volatile_v; -#endif + #endif //*************************************************************************** /// remove_volatile ///\ingroup type_traits - template struct remove_volatile : std::remove_volatile {}; + template + struct remove_volatile : std::remove_volatile + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_volatile_t = typename std::remove_volatile::type; -#endif + #endif //*************************************************************************** /// add_volatile ///\ingroup type_traits - template struct add_volatile : std::add_volatile {}; + template + struct add_volatile : std::add_volatile + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_volatile_t = typename std::add_volatile::type; -#endif + #endif //*************************************************************************** /// remove_cv ///\ingroup type_traits - template struct remove_cv : std::remove_cv {}; + template + struct remove_cv : std::remove_cv + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_cv_t = typename std::remove_cv::type; -#endif + #endif //*************************************************************************** /// add_cv ///\ingroup type_traits - template struct add_cv : std::add_cv {}; + template + struct add_cv : std::add_cv + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_cv_t = typename std::add_cv::type; -#endif + #endif //*************************************************************************** /// remove_cvref ///\ingroup type_traits - template struct remove_cvref + template + struct remove_cvref { typedef typename std::remove_cv::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_cvref_t = typename etl::remove_cvref::type; -#endif + #endif //*************************************************************************** /// is_integral ///\ingroup type_traits - template struct is_integral : std::is_integral {}; + template + struct is_integral : std::is_integral + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_integral_v = std::is_integral_v; -#endif + #endif //*************************************************************************** /// is_signed ///\ingroup type_traits - template struct is_signed : std::is_signed {}; + template + struct is_signed : std::is_signed + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_signed_v = std::is_signed_v; -#endif + #endif //*************************************************************************** /// is_unsigned ///\ingroup type_traits - template struct is_unsigned : std::is_unsigned {}; + template + struct is_unsigned : std::is_unsigned + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_unsigned_v = std::is_unsigned_v; -#endif + #endif //*************************************************************************** /// is_floating_point ///\ingroup type_traits - template struct is_floating_point : std::is_floating_point {}; + template + struct is_floating_point : std::is_floating_point + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_floating_point_v = std::is_floating_point_v; -#endif + #endif //*************************************************************************** /// is_same ///\ingroup type_traits - template struct is_same : std::is_same {}; + template + struct is_same : std::is_same + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_same_v = std::is_same_v; -#endif + #endif //*************************************************************************** /// is_void ///\ingroup type_traits - template struct is_void : std::is_void {}; + template + struct is_void : std::is_void + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_void_v = std::is_void_v; -#endif + #endif //*************************************************************************** /// is_arithmetic ///\ingroup type_traits - template struct is_arithmetic : std::is_arithmetic {}; + template + struct is_arithmetic : std::is_arithmetic + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_arithmetic_v = std::is_arithmetic_v; -#endif + #endif //*************************************************************************** /// is_fundamental ///\ingroup type_traits - template struct is_fundamental : std::is_fundamental {}; + template + struct is_fundamental : std::is_fundamental + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_fundamental_v = std::is_fundamental_v; -#endif + #endif //*************************************************************************** /// is_compound ///\ingroup type_traits - template struct is_compound : std::is_compound {}; + template + struct is_compound : std::is_compound + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_compound_v = std::is_compound_v; -#endif + #endif //*************************************************************************** /// is_array ///\ingroup type_traits - template struct is_array : std::is_array {}; + template + struct is_array : std::is_array + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_array_v = std::is_array_v; -#endif + #endif //*************************************************************************** /// is_pointer ///\ingroup type_traits - template struct is_pointer : std::is_pointer {}; + template + struct is_pointer : std::is_pointer + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_pointer_v = std::is_pointer_v; -#endif + #endif //*************************************************************************** /// is_reference ///\ingroup type_traits - template struct is_reference : std::is_reference {}; + template + struct is_reference : std::is_reference + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_reference_v = std::is_reference_v; -#endif + #endif //*************************************************************************** /// is_lvalue_reference ///\ingroup type_traits - template struct is_lvalue_reference : std::is_lvalue_reference {}; + template + struct is_lvalue_reference : std::is_lvalue_reference + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_lvalue_reference_v = std::is_lvalue_reference_v; -#endif + #endif - //*************************************************************************** - /// is_rvalue_reference - ///\ingroup type_traits -#if ETL_USING_CPP11 - template struct is_rvalue_reference : std::is_rvalue_reference {}; + //*************************************************************************** + /// is_rvalue_reference + ///\ingroup type_traits + #if ETL_USING_CPP11 + template + struct is_rvalue_reference : std::is_rvalue_reference + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_rvalue_reference_v = std::is_rvalue_reference_v; -#endif -#endif + #endif + #endif //*************************************************************************** /// is_pod ///\ingroup type_traits template - struct is_pod : std::integral_constant::value && std::is_trivially_default_constructible::value && std::is_trivially_copyable::value> {}; + struct is_pod : std::integral_constant::value && std::is_trivially_default_constructible::value && std::is_trivially_copyable::value> + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_pod_v = std::is_standard_layout_v && std::is_trivially_default_constructible_v && std::is_trivially_copyable_v; -#endif + #endif -#if defined(ETL_COMPILER_GCC) - #if ETL_COMPILER_VERSION >= 5 - #define ETL_GCC_V5_TYPE_TRAITS_SUPPORTED - #endif -#endif + #if defined(ETL_COMPILER_GCC) + #if ETL_COMPILER_VERSION >= 5 + #define ETL_GCC_V5_TYPE_TRAITS_SUPPORTED + #endif + #endif //*************************************************************************** /// conditional ///\ingroup type_traits - template struct conditional { typedef T type; }; - template struct conditional { typedef F type; }; + template + struct conditional + { + typedef T type; + }; + template + struct conditional + { + typedef F type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using conditional_t = typename conditional::type; -#endif + #endif //*************************************************************************** /// make_signed ///\ingroup type_traits - template struct make_signed : std::make_signed {}; + template + struct make_signed : std::make_signed + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using make_signed_t = typename std::make_signed::type; -#endif + #endif //*************************************************************************** /// make_unsigned ///\ingroup type_traits - template struct make_unsigned : std::make_unsigned {}; + template + struct make_unsigned : std::make_unsigned + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using make_unsigned_t = typename std::make_unsigned::type; -#endif + #endif //*************************************************************************** /// enable_if ///\ingroup type_traits - template struct enable_if : std::enable_if {}; + template + struct enable_if : std::enable_if + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using enable_if_t = typename std::enable_if::type; -#endif + #endif //*************************************************************************** /// extent ///\ingroup type_traits template - struct extent : std::extent {}; + struct extent : std::extent + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t extent_v = std::extent_v; -#endif + #endif //*************************************************************************** /// remove_extent ///\ingroup type_traits - template struct remove_extent : std::remove_extent { }; + template + struct remove_extent : std::remove_extent + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_extent_t = typename std::remove_extent::type; -#endif + #endif //*************************************************************************** /// remove_all_extents ///\ingroup type_traits - template struct remove_all_extents : std::remove_all_extents { }; + template + struct remove_all_extents : std::remove_all_extents + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using remove_all_extents_t = typename std::remove_all_extents::type; -#endif + #endif //*************************************************************************** /// rank ///\ingroup type_traits - template struct rank : std::rank {}; + template + struct rank : std::rank + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t rank_v = std::rank_v; -#endif + #endif //*************************************************************************** /// decay ///\ingroup type_traits - template struct decay : std::decay {}; + template + struct decay : std::decay + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using decay_t = typename std::decay::type; -#endif + #endif //*************************************************************************** /// is_base_of ///\ingroup type_traits - template struct is_base_of : std::is_base_of {}; + template + struct is_base_of : std::is_base_of + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_base_of_v = std::is_base_of_v; -#endif + #endif //*************************************************************************** /// is_class - template struct is_class : std::is_class{}; + template + struct is_class : std::is_class + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_class_v = is_class::value; -#endif + #endif //*************************************************************************** /// add_lvalue_reference - template struct add_lvalue_reference : std::add_lvalue_reference {}; + template + struct add_lvalue_reference : std::add_lvalue_reference + { + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_lvalue_reference_t = typename std::add_lvalue_reference::type; -#endif + #endif - //*************************************************************************** - /// add_rvalue_reference -#if ETL_USING_CPP11 - template struct add_rvalue_reference : std::add_rvalue_reference {}; -#endif + //*************************************************************************** + /// add_rvalue_reference + #if ETL_USING_CPP11 + template + struct add_rvalue_reference : std::add_rvalue_reference + { + }; + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using add_rvalue_reference_t = typename std::add_rvalue_reference::type; -#endif + #endif - //*************************************************************************** - /// declval -#if ETL_USING_CPP11 + //*************************************************************************** + /// declval + #if ETL_USING_CPP11 template typename std::add_rvalue_reference::type declval() ETL_NOEXCEPT; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// is_enum ///\ingroup type_traits @@ -1387,25 +2063,28 @@ typedef integral_constant true_type; { }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_enum_v = etl::is_enum::value; -#endif + #endif -#endif + #endif - //*************************************************************************** - /// is_convertible - ///\ingroup type_traits -#if ETL_USING_CPP11 + //*************************************************************************** + /// is_convertible + ///\ingroup type_traits + #if ETL_USING_CPP11 template - struct is_convertible : std::is_convertible {}; + struct is_convertible : std::is_convertible + { + }; // Is convertible and the conversion is noexcept. template struct is_nothrow_convertible { private: + // Helper: a function taking TTo to require the conversion. static void sink(TTo) noexcept; @@ -1418,40 +2097,50 @@ typedef integral_constant true_type; static etl::false_type test(...); public: + static ETL_CONSTANT bool value = decltype(test(0))::value; }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_convertible_v = std::is_convertible_v; template inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible::value; -#endif + #endif //*************************************************************************** /// Alignment templates. ///\ingroup type_traits - template struct alignment_of : std::alignment_of {}; - template <> struct alignment_of : std::integral_constant {}; - template <> struct alignment_of : std::integral_constant {}; + template + struct alignment_of : std::alignment_of + { + }; + template <> + struct alignment_of : std::integral_constant + { + }; + template <> + struct alignment_of : std::integral_constant + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t alignment_of_v = std::alignment_of_v; -#endif + #endif -#endif // Condition = ETL_USING_STL && ETL_USING_CPP11 + #endif // Condition = ETL_USING_STL && ETL_USING_CPP11 //*************************************************************************** // ETL extended type traits. //*************************************************************************** -#if ETL_USING_CPP11 - //*************************************************************************** - /// conjunction -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 + //*************************************************************************** + /// conjunction + #if ETL_USING_CPP11 template struct conjunction : public etl::true_type { @@ -1466,16 +2155,16 @@ typedef integral_constant true_type; struct conjunction : public T { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool conjunction_v = conjunction::value; -#endif + #endif - //*************************************************************************** - /// disjunction -#if ETL_USING_CPP11 + //*************************************************************************** + /// disjunction + #if ETL_USING_CPP11 template struct disjunction : public etl::false_type { @@ -1486,21 +2175,22 @@ typedef integral_constant true_type; { }; - template struct disjunction : public T1 + template + struct disjunction : public T1 { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool disjunction_v = etl::disjunction::value; -#endif + #endif -#endif + #endif //*************************************************************************** /// exclusive_disjunction -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template struct exclusive_disjunction; @@ -1514,12 +2204,12 @@ typedef integral_constant true_type; struct exclusive_disjunction : public etl::exclusive_disjunction::value && !etl::conjunction::value>, TRest...> { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool exclusive_disjunction_v = etl::exclusive_disjunction::value; -#endif + #endif //*************************************************************************** /// conditional_integral_constant @@ -1541,7 +2231,7 @@ typedef integral_constant true_type; static const T value = FALSE_VALUE; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types @@ -1549,71 +2239,76 @@ typedef integral_constant true_type; struct is_one_of : etl::disjunction...> { }; -#else - /*[[[cog + #else + /*[[[cog import cog cog.outl("//***************************************************************************") cog.outl("/// Template to determine if a type is one of a specified list.") cog.outl("///\\ingroup types") cog.outl("template " % IsOneOf) + cog.out(" ") + cog.outl(" typename T%s = void>" % IsOneOf) cog.outl("struct is_one_of") cog.outl("{") - cog.outl(" static const bool value = ") - for n in range(1, int(IsOneOf)): - cog.outl(" etl::is_same::value ||" % n) - cog.outl(" etl::is_same::value;" % IsOneOf) + cog.out(" static const bool value = etl::is_same::value") + for n in range(2, int(IsOneOf) + 1): + if n == int(IsOneOf): + cog.outl(" || etl::is_same::value;" % n) + elif (n - 1) % 4 == 0: + cog.outl("") + cog.out(" || etl::is_same::value" % n) + else: + cog.out(" || etl::is_same::value" % n) cog.outl("};") ]]]*/ - /*[[[end]]]*/ -#endif + /*[[[end]]]*/ + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_one_of_v = etl::is_one_of::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 namespace private_type_traits { //*************************************************************************** // Helper to count occurrences of a type in a list of types - template + template struct count_type; // Base case: zero occurrences - template + template struct count_type : etl::integral_constant { }; // Recursive case: increment count if head is the same as T, otherwise continue with tail - template + template struct count_type : etl::integral_constant::value ? 1 : 0) + count_type::value> { }; - } + } // namespace private_type_traits - template + template struct has_duplicates_of : etl::integral_constant::value > 1)> { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types @@ -1621,14 +2316,14 @@ typedef integral_constant true_type; struct is_base_of_all : etl::conjunction...> { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of any type in a specified list. ///\ingroup types @@ -1637,17 +2332,17 @@ typedef integral_constant true_type; { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_base_of_any_v = etl::is_base_of_any::value; -#endif + #endif //*************************************************************************** /// Get the Nth base of a recursively inherited type. /// Requires that the class has defined 'base_type'. - //*************************************************************************** + //*************************************************************************** // Recursive definition of the type. template struct nth_base @@ -1661,10 +2356,10 @@ typedef integral_constant true_type; typedef TType type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using nth_base_t = typename nth_base::type; -#endif + #endif //*************************************************************************** /// A set of templates to allow related types to be derived. @@ -1687,9 +2382,9 @@ typedef integral_constant true_type; typedef const type_t* const_pointer; typedef const type_t* const const_pointer_const; -#if ETL_USING_CPP11 - typedef type_t&& rvalue_reference; -#endif + #if ETL_USING_CPP11 + typedef type_t&& rvalue_reference; + #endif }; // Pointers. @@ -1709,9 +2404,9 @@ typedef integral_constant true_type; typedef const type_t* const_pointer; typedef const type_t* const const_pointer_const; -#if ETL_USING_CPP11 - typedef type_t&& rvalue_reference; -#endif + #if ETL_USING_CPP11 + typedef type_t&& rvalue_reference; + #endif }; // Pointers. @@ -1728,12 +2423,12 @@ typedef integral_constant true_type; typedef type_t& reference; typedef const type_t& const_reference; typedef type_t* pointer; - typedef const type_t* const_pointer; + typedef const type_t* const_pointer; typedef const type_t* const const_pointer_const; -#if ETL_USING_CPP11 - typedef type_t&& rvalue_reference; -#endif + #if ETL_USING_CPP11 + typedef type_t&& rvalue_reference; + #endif }; // References. @@ -1753,12 +2448,12 @@ typedef integral_constant true_type; typedef const type_t* const_pointer; typedef const type_t* const const_pointer_const; -#if ETL_USING_CPP11 - typedef type_t&& rvalue_reference; -#endif + #if ETL_USING_CPP11 + typedef type_t&& rvalue_reference; + #endif }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 // rvalue References. template struct types @@ -1776,13 +2471,13 @@ typedef integral_constant true_type; typedef const type_t* const_pointer; typedef const type_t* const const_pointer_const; -#if ETL_USING_CPP11 - typedef type_t&& rvalue_reference; -#endif + #if ETL_USING_CPP11 + typedef type_t&& rvalue_reference; + #endif }; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using types_t = typename types::type; @@ -1803,35 +2498,41 @@ typedef integral_constant true_type; template using types_cpc = typename types::const_pointer_const; -#endif + #endif //*************************************************************************** /// size_of ///\ingroup types - template struct size_of : etl::integral_constant {}; - template <> struct size_of : etl::integral_constant {}; + template + struct size_of : etl::integral_constant + { + }; + template <> + struct size_of : etl::integral_constant + { + }; -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t size_of_v = etl::size_of::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// are_all_same template struct are_all_same : etl::conjunction...> { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool are_all_same_v = are_all_same::value; -#endif + #endif //*************************************************************************** -#if ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) && ((!defined(ARDUINO) && ETL_NOT_USING_STLPORT) || defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED)) + #if ETL_USING_STL && ETL_USING_CPP11 && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) && ((!defined(ARDUINO) && ETL_NOT_USING_STLPORT) || defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED)) //********************************************* // Use the STL's definitions. @@ -1839,12 +2540,12 @@ typedef integral_constant true_type; //********************************************* // is_assignable - template + template using is_assignable = std::is_assignable; //********************************************* // is_constructible - template + template using is_constructible = std::is_constructible; //********************************************* @@ -1857,57 +2558,57 @@ typedef integral_constant true_type; template using is_move_constructible = std::is_move_constructible; - //********************************************* - // is_trivially_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + //********************************************* + // is_trivially_constructible + #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_constructible = std::is_trivially_constructible; -#else + #else template using is_trivially_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif + #endif - //********************************************* - // is_trivially_copy_constructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + //********************************************* + // is_trivially_copy_constructible + #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_constructible = std::is_trivially_copy_constructible; -#else + #else template using is_trivially_copy_constructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif + #endif - //********************************************* - // is_trivially_destructible -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + //********************************************* + // is_trivially_destructible + #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_destructible = std::is_trivially_destructible; -#else + #else template using is_trivially_destructible = etl::bool_constant::value || etl::is_pointer::value>; -#endif + #endif - //********************************************* - // is_trivially_copy_assignable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + //********************************************* + // is_trivially_copy_assignable + #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copy_assignable = std::is_trivially_copy_assignable; -#else + #else template using is_trivially_copy_assignable = etl::bool_constant::value || etl::is_pointer::value>; -#endif + #endif - //********************************************* - // is_trivially_copyable -#if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED + //********************************************* + // is_trivially_copyable + #if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED template using is_trivially_copyable = std::is_trivially_copyable; -#else + #else template using is_trivially_copyable = etl::bool_constant::value || etl::is_pointer::value>; -#endif + #endif -#elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) + #elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) //********************************************* // Use the compiler's builtins. @@ -1915,24 +2616,24 @@ typedef integral_constant true_type; //********************************************* // is_assignable - template + template struct is_assignable { static ETL_CONSTANT bool value = __is_assignable(T1, T2); }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // is_constructible - template + template struct is_constructible { static ETL_CONSTANT bool value = __is_constructible(T, TArgs...); }; -#else + #else //********************************************* // is_constructible - template + template struct is_constructible { static ETL_CONSTANT bool value = __is_constructible(T, TArgs); @@ -1940,12 +2641,12 @@ typedef integral_constant true_type; //********************************************* // is_constructible - template + template struct is_constructible { static ETL_CONSTANT bool value = __is_constructible(T); }; -#endif + #endif //********************************************* // is_copy_constructible @@ -1961,29 +2662,29 @@ typedef integral_constant true_type; { }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // is_trivially_constructible template struct is_trivially_constructible { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_constructor(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs...); -#endif + #endif }; -#else + #else //********************************************* // is_trivially_constructible template struct is_trivially_constructible { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_constructor(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_constructible(T, TArgs); -#endif + #endif }; //********************************************* @@ -1991,13 +2692,13 @@ typedef integral_constant true_type; template struct is_trivially_constructible { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_constructor(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_constructible(T); -#endif + #endif }; -#endif + #endif //********************************************* // is_trivially_copy_constructible @@ -2011,11 +2712,11 @@ typedef integral_constant true_type; template struct is_trivially_destructible { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_destructor(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_destructible(T); -#endif + #endif }; //********************************************* @@ -2023,11 +2724,11 @@ typedef integral_constant true_type; template struct is_trivially_copy_assignable { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_copy(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_copyable(T); -#endif + #endif }; //********************************************* @@ -2035,14 +2736,14 @@ typedef integral_constant true_type; template struct is_trivially_copyable { -#if defined(ETL_COMPILER_GCC) + #if defined(ETL_COMPILER_GCC) static ETL_CONSTANT bool value = __has_trivial_copy(T); -#else + #else static ETL_CONSTANT bool value = __is_trivially_copyable(T); -#endif + #endif }; -#elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) + #elif defined(ETL_USER_DEFINED_TYPE_TRAITS) && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) //********************************************* // Force the user to provide specialisations for @@ -2064,7 +2765,7 @@ typedef integral_constant true_type; template struct is_assignable; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // is_constructible template @@ -2082,7 +2783,7 @@ typedef integral_constant true_type; struct is_constructible : public is_constructible_helper::value || etl::is_pointer::value, TArgs...> { }; -#endif + #endif //********************************************* // is_copy_constructible @@ -2175,7 +2876,7 @@ typedef integral_constant true_type; template struct is_trivially_copyable; -#else + #else //********************************************* // Assume that anything other than arithmetics @@ -2189,17 +2890,21 @@ typedef integral_constant true_type; { }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //*************************************************************************** /// is_constructible - namespace private_type_traits + namespace private_type_traits { template - struct is_constructible_ : etl::false_type {}; + struct is_constructible_ : etl::false_type + { + }; template - struct is_constructible_()...))>, T, TArgs...> : etl::true_type {}; - } + struct is_constructible_()...))>, T, TArgs...> : etl::true_type + { + }; + } // namespace private_type_traits //********************************************* // is_constructible @@ -2208,21 +2913,51 @@ typedef integral_constant true_type; //********************************************* // is_copy_constructible - template struct is_copy_constructible : public is_constructible::type>::type>{}; - template <> struct is_copy_constructible : public false_type{}; - template <> struct is_copy_constructible : public false_type{}; - template <> struct is_copy_constructible : public false_type{}; - template <> struct is_copy_constructible : public false_type{}; + template + struct is_copy_constructible : public is_constructible::type>::type> + { + }; + template <> + struct is_copy_constructible : public false_type + { + }; + template <> + struct is_copy_constructible : public false_type + { + }; + template <> + struct is_copy_constructible : public false_type + { + }; + template <> + struct is_copy_constructible : public false_type + { + }; //********************************************* // is_move_constructible - template struct is_move_constructible: public is_constructible::type>{}; - template <> struct is_move_constructible : public false_type{}; - template <> struct is_move_constructible : public false_type{}; - template <> struct is_move_constructible : public false_type{}; - template <> struct is_move_constructible : public false_type{}; + template + struct is_move_constructible : public is_constructible::type> + { + }; + template <> + struct is_move_constructible : public false_type + { + }; + template <> + struct is_move_constructible : public false_type + { + }; + template <> + struct is_move_constructible : public false_type + { + }; + template <> + struct is_move_constructible : public false_type + { + }; -#else + #else //********************************************* // is_copy_constructible @@ -2237,7 +2972,7 @@ typedef integral_constant true_type; struct is_move_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; -#endif + #endif //********************************************* // is_trivially_constructible @@ -2274,30 +3009,33 @@ typedef integral_constant true_type; { }; -#endif + #endif template - struct is_lvalue_assignable : public etl::is_assignable::type, - typename etl::add_lvalue_reference::type>::type> + struct is_lvalue_assignable : public etl::is_assignable::type, typename etl::add_lvalue_reference::type>::type> { }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // is_default_constructible - template - struct is_default_constructible : etl::false_type { }; + template + struct is_default_constructible : etl::false_type + { + }; - template - struct is_default_constructible> : etl::true_type { }; -#else + template + struct is_default_constructible> : etl::true_type + { + }; + #else template struct is_default_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; -#endif + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool is_assignable_v = etl::is_assignable::value; @@ -2305,16 +3043,16 @@ typedef integral_constant true_type; template inline constexpr bool is_lvalue_assignable_v = etl::is_lvalue_assignable::value; - template + template inline constexpr bool is_constructible_v = etl::is_constructible::value; - template + template inline constexpr bool is_default_constructible_v = etl::is_default_constructible::value; - template + template inline constexpr bool is_copy_constructible_v = etl::is_copy_constructible::value; - template + template inline constexpr bool is_move_constructible_v = etl::is_move_constructible::value; template @@ -2332,9 +3070,9 @@ typedef integral_constant true_type; template inline constexpr bool is_trivially_copyable_v = etl::is_trivially_copyable::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // common_type // Based on the sample implementation detailed on @@ -2342,7 +3080,7 @@ typedef integral_constant true_type; //********************************************* //*********************************** // Primary template - template + template struct common_type { }; @@ -2371,7 +3109,7 @@ typedef integral_constant true_type; }; template - struct common_type_2_impl + struct common_type_2_impl : decay_conditional_result { }; @@ -2381,16 +3119,16 @@ typedef integral_constant true_type; : decay_conditional_result { }; - } + } // namespace private_common_type //*********************************** // Two types template struct common_type - : etl::conditional::type>::value&& etl::is_same::type>::value, + : etl::conditional::type>::value && etl::is_same::type>::value, private_common_type::common_type_2_impl, common_type::type, - typename etl::decay::type>>::type + typename etl::decay::type>>::type { }; @@ -2408,9 +3146,9 @@ typedef integral_constant true_type; : common_type::type, TRest...> { }; - } + } // namespace private_common_type - template + template struct common_type : private_common_type::common_type_multi_impl { @@ -2418,7 +3156,7 @@ typedef integral_constant true_type; template using common_type_t = typename common_type::type; -#endif + #endif //*************************************************************************** /// Defines one of five unsigned types that has the same size as T. @@ -2427,16 +3165,16 @@ typedef integral_constant true_type; struct unsigned_type { typedef typename etl::conditional::type>::type>::type>::type type; + typename etl::conditional::type>::type>::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using unsigned_type_t = typename unsigned_type::type; -#endif + #endif //*************************************************************************** /// Defines one of five signed types that has the same size as T. @@ -2445,31 +3183,34 @@ typedef integral_constant true_type; struct signed_type { typedef typename etl::conditional::type>::type>::type>::type type; + typename etl::conditional::type>::type>::type>::type type; }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using signed_type_t = typename signed_type::type; -#endif + #endif //********************************************* // type_identity template - struct type_identity { typedef T type; }; + struct type_identity + { + typedef T type; + }; -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using type_identity_t = typename type_identity::type; -#endif + #endif //********************************************* // underlying_type -#if ETL_USING_BUILTIN_UNDERLYING_TYPE + #if ETL_USING_BUILTIN_UNDERLYING_TYPE // Primary template for etl::underlying_type template ::value> struct underlying_type; @@ -2487,7 +3228,7 @@ typedef integral_constant true_type; { typedef __underlying_type(T) type; }; -#else + #else /// Primary template for etl::underlying_type /// Users must specialise this template for their enumerations. template @@ -2495,76 +3236,86 @@ typedef integral_constant true_type; { typedef int type; }; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 template using underlying_type_t = typename underlying_type::type; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // has_duplicates template struct has_duplicates; template - struct has_duplicates : etl::conditional_t::value, - etl::true_type, - has_duplicates> {}; + struct has_duplicates : etl::conditional_t::value, etl::true_type, has_duplicates> + { + }; template - struct has_duplicates : etl::false_type {}; + struct has_duplicates : etl::false_type + { + }; template <> - struct has_duplicates<> : etl::false_type {}; -#endif + struct has_duplicates<> : etl::false_type + { + }; + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr bool has_duplicates_v = etl::has_duplicates::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* // count_of template struct count_of; template - struct count_of : etl::integral_constant::value + - count_of::value> {}; + struct count_of : etl::integral_constant::value + count_of::value> + { + }; template - struct count_of : etl::integral_constant {}; -#endif + struct count_of : etl::integral_constant + { + }; + #endif -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 template inline constexpr size_t count_of_v = etl::count_of::value; -#endif + #endif -#if ETL_USING_CPP11 + #if ETL_USING_CPP11 //********************************************* /// is_specialization template class Template> - struct is_specialization : etl::false_type {}; + struct is_specialization : etl::false_type + { + }; template