diff options
author | mrsmidge <smidge@xsco.net> | 2019-08-15 23:14:03 +0100 |
---|---|---|
committer | mrsmidge <smidge@xsco.net> | 2019-08-15 23:14:03 +0100 |
commit | c5323b155eb9c2815087580d635765a9aea89fca (patch) | |
tree | 24b61b0c654fe402bf083b2270475006e31c4a51 | |
parent | 6c30925688bbe8b448304c3a819b1c62da6edf9d (diff) |
clang-format cleanup
-rw-r--r-- | .clang-format | 13 | ||||
-rw-r--r-- | include/djinterop/exceptions.hpp | 29 | ||||
-rw-r--r-- | include/djinterop/optional/optional.hpp | 1582 | ||||
-rw-r--r-- | include/djinterop/pad_color.hpp | 7 | ||||
-rw-r--r-- | include/djinterop/semantic_version.hpp | 16 | ||||
-rw-r--r-- | include/djinterop/track.hpp | 51 | ||||
-rwxr-xr-x | print_todo.sh | 2 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/schema.hpp | 10 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/schema_1_6_0.hpp | 8 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/schema_1_7_1.hpp | 8 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/schema_validate_utils.hpp | 26 | ||||
-rw-r--r-- | src/djinterop/impl/track_impl.hpp | 3 | ||||
-rw-r--r-- | src/djinterop/impl/util.hpp | 9 |
13 files changed, 981 insertions, 783 deletions
diff --git a/.clang-format b/.clang-format index de0dd55..a90ead2 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,5 @@ --- +# Compatible with clang-format 6.0.0 Language: Cpp # BasedOnStyle: Google AccessModifierOffset: -4 @@ -41,17 +42,17 @@ BreakBeforeBraces: Allman BreakBeforeInheritanceComma: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BreakConstructorInitializers: BeforeColon +BreakConstructorInitializers: AfterColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true ColumnLimit: 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DerivePointerAlignment: true +DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false FixNamespaceComments: true @@ -93,7 +94,7 @@ PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 200 PointerAlignment: Left RawStringFormats: - - Delimiters: [ 'pb' ] + - Delimiter: 'pb' Language: TextProto BasedOnStyle: google ReflowComments: true @@ -110,8 +111,8 @@ SpacesInContainerLiterals: true SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 8 +Standard: Cpp03 +TabWidth: 4 UseTab: Never ... diff --git a/include/djinterop/exceptions.hpp b/include/djinterop/exceptions.hpp index d94ee3a..65c774c 100644 --- a/include/djinterop/exceptions.hpp +++ b/include/djinterop/exceptions.hpp @@ -33,7 +33,7 @@ namespace djinterop class database_inconsistency : public std::runtime_error { public: - explicit database_inconsistency(const std::string &what_arg) noexcept + explicit database_inconsistency(const std::string& what_arg) noexcept : runtime_error{what_arg} { } @@ -45,15 +45,16 @@ public: class unsupported_database_version : public std::runtime_error { public: - explicit unsupported_database_version( - const semantic_version version) noexcept - : runtime_error{"Unsupported database version"}, version_{version} + explicit unsupported_database_version(const semantic_version version) + noexcept : runtime_error{"Unsupported database version"}, + version_{version} { } explicit unsupported_database_version( - const std::string &what_arg, const semantic_version version) noexcept - : runtime_error{what_arg}, version_{version} + const std::string& what_arg, const semantic_version version) noexcept + : runtime_error{what_arg}, + version_{version} { } @@ -70,7 +71,8 @@ class crate_deleted : public std::runtime_error public: /// Constructs the exception for a given crate ID explicit crate_deleted(int64_t id) noexcept - : runtime_error{"Crate does not exist in database anymore"}, id_{id} + : runtime_error{"Crate does not exist in database anymore"}, + id_{id} { } @@ -88,8 +90,9 @@ class crate_database_inconsistency : public database_inconsistency public: /// Construct the exception for a given crate ID explicit crate_database_inconsistency( - const std::string &what_arg, int64_t id) noexcept - : database_inconsistency{what_arg.c_str()}, id_{id} + const std::string& what_arg, int64_t id) noexcept + : database_inconsistency{what_arg.c_str()}, + id_{id} { } @@ -107,7 +110,8 @@ class track_deleted : public std::invalid_argument public: /// Constructs the exception for a given track ID explicit track_deleted(int64_t id) noexcept - : invalid_argument{"Track does not exist in database"}, id_{id} + : invalid_argument{"Track does not exist in database"}, + id_{id} { } @@ -125,8 +129,9 @@ class track_database_inconsistency : public database_inconsistency public: /// Construct the exception for a given track ID explicit track_database_inconsistency( - const std::string &what_arg, int64_t id) noexcept - : database_inconsistency{what_arg}, id_{id} + const std::string& what_arg, int64_t id) noexcept + : database_inconsistency{what_arg}, + id_{id} { } diff --git a/include/djinterop/optional/optional.hpp b/include/djinterop/optional/optional.hpp index 8db9317..9fed1b1 100644 --- a/include/djinterop/optional/optional.hpp +++ b/include/djinterop/optional/optional.hpp @@ -7,1060 +7,1246 @@ // The idea and interface is based on Boost.Optional library // authored by Fernando Luis Cacciola Carballal -# ifndef ___OPTIONAL_HPP___ -# define ___OPTIONAL_HPP___ - -# include <utility> -# include <type_traits> -# include <initializer_list> -# include <cassert> -# include <functional> -# include <string> -# include <stdexcept> - -# define TR2_OPTIONAL_REQUIRES(...) typename enable_if<__VA_ARGS__::value, bool>::type = false - -# if defined __GNUC__ // NOTE: GNUC is also defined for Clang -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# endif +#ifndef ___OPTIONAL_HPP___ +#define ___OPTIONAL_HPP___ + +#include <cassert> +#include <functional> +#include <initializer_list> +#include <stdexcept> +#include <string> +#include <type_traits> +#include <utility> + +#define TR2_OPTIONAL_REQUIRES(...) \ + typename enable_if<__VA_ARGS__::value, bool>::type = false + +#if defined __GNUC__ // NOTE: GNUC is also defined for Clang +#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) +#define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ +#elif (__GNUC__ > 4) +#define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ +#endif # -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# endif +#if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) +#define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ +#elif (__GNUC__ > 4) +#define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ +#endif # -# if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# endif -# endif +#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) +#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ +#elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) +#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ +#elif (__GNUC__ > 4) +#define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ +#endif +#endif # -# if defined __clang_major__ -# if (__clang_major__ == 3 && __clang_minor__ >= 5) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# elif (__clang_major__ > 3) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# endif -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# endif -# endif +#if defined __clang_major__ +#if (__clang_major__ == 3 && __clang_minor__ >= 5) +#define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ +#elif (__clang_major__ > 3) +#define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ +#endif +#if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ +#define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ +#elif ( \ + __clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) +#define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ +#endif +#endif # -# if defined _MSC_VER -# if (_MSC_VER >= 1900) -# define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# endif -# endif - -# if defined __clang__ -# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif -# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif - - -# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 -# define OPTIONAL_CONSTEXPR_INIT_LIST constexpr -# else -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 -# define OPTIONAL_CONSTEXPR_INIT_LIST -# endif - -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L) -# define OPTIONAL_HAS_MOVE_ACCESSORS 1 -# else -# define OPTIONAL_HAS_MOVE_ACCESSORS 0 -# endif - -# // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr -# if (defined __cplusplus) && (__cplusplus == 201103L) -# define OPTIONAL_MUTABLE_CONSTEXPR -# else -# define OPTIONAL_MUTABLE_CONSTEXPR constexpr -# endif - -namespace std{ - -namespace experimental{ +#if defined _MSC_VER +#if (_MSC_VER >= 1900) +#define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ +#endif +#endif +#if defined __clang__ +#if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) +#define OPTIONAL_HAS_THIS_RVALUE_REFS 1 +#else +#define OPTIONAL_HAS_THIS_RVALUE_REFS 0 +#endif +#elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ +#define OPTIONAL_HAS_THIS_RVALUE_REFS 1 +#elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ +#define OPTIONAL_HAS_THIS_RVALUE_REFS 1 +#else +#define OPTIONAL_HAS_THIS_RVALUE_REFS 0 +#endif + +#if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ +#define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 +#define OPTIONAL_CONSTEXPR_INIT_LIST constexpr +#else +#define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 +#define OPTIONAL_CONSTEXPR_INIT_LIST +#endif + +#if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && \ + (__cplusplus != 201103L) +#define OPTIONAL_HAS_MOVE_ACCESSORS 1 +#else +#define OPTIONAL_HAS_MOVE_ACCESSORS 0 +#endif + +#// In C++11 constexpr implies const, so we need to make non-const members also non-constexpr +#if (defined __cplusplus) && (__cplusplus == 201103L) +#define OPTIONAL_MUTABLE_CONSTEXPR +#else +#define OPTIONAL_MUTABLE_CONSTEXPR constexpr +#endif + +namespace std +{ +namespace experimental +{ // BEGIN workaround for missing is_trivially_destructible -# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it: it is already there -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - template <typename T> - using is_trivially_destructible = std::has_trivial_destructor<T>; -# endif +#if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ +// leave it: it is already there +#elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ +// leave it: it is already there +#elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ +// leave it: it is already there +#elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS +// leave it: the user doesn't want it +#else +template <typename T> +using is_trivially_destructible = std::has_trivial_destructor<T>; +#endif // END workaround for missing is_trivially_destructible -# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - +#if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) +// leave it; our metafunctions are already defined. +#elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ +// leave it; our metafunctions are already defined. +#elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ +// leave it: it is already there +#elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS +// leave it: the user doesn't want it +#else // workaround for missing traits in GCC and CLANG template <class T> struct is_nothrow_move_constructible { - constexpr static bool value = std::is_nothrow_constructible<T, T&&>::value; + constexpr static bool value = std::is_nothrow_constructible<T, T&&>::value; }; - template <class T, class U> struct is_assignable { - template <class X, class Y> - constexpr static bool has_assign(...) { return false; } + template <class X, class Y> + constexpr static bool has_assign(...) + { + return false; + } - template <class X, class Y, size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true)) > - // the comma operator is necessary for the cases where operator= returns void - constexpr static bool has_assign(bool) { return true; } + template < + class X, class Y, + size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true))> + // the comma operator is necessary for the cases where operator= returns + // void + constexpr static bool has_assign(bool) + { + return true; + } - constexpr static bool value = has_assign<T, U>(true); + constexpr static bool value = has_assign<T, U>(true); }; - template <class T> struct is_nothrow_move_assignable { - template <class X, bool has_any_move_assign> - struct has_nothrow_move_assign { - constexpr static bool value = false; - }; - - template <class X> - struct has_nothrow_move_assign<X, true> { - constexpr static bool value = noexcept( std::declval<X&>() = std::declval<X&&>() ); - }; - - constexpr static bool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value; + template <class X, bool has_any_move_assign> + struct has_nothrow_move_assign + { + constexpr static bool value = false; + }; + + template <class X> + struct has_nothrow_move_assign<X, true> + { + constexpr static bool value = + noexcept(std::declval<X&>() = std::declval<X&&>()); + }; + + constexpr static bool value = + has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value; }; // end workaround - -# endif - - +#endif // 20.5.4, optional for object types -template <class T> class optional; +template <class T> +class optional; // 20.5.5, optional for lvalue reference types -template <class T> class optional<T&>; - +template <class T> +class optional<T&>; // workaround: std utility functions aren't constexpr yet -template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type& t) noexcept +template <class T> +inline constexpr T&& constexpr_forward( + typename std::remove_reference<T>::type& t) noexcept { - return static_cast<T&&>(t); + return static_cast<T&&>(t); } -template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type&& t) noexcept +template <class T> +inline constexpr T&& constexpr_forward( + typename std::remove_reference<T>::type&& t) noexcept { static_assert(!std::is_lvalue_reference<T>::value, "!!"); return static_cast<T&&>(t); } -template <class T> inline constexpr typename std::remove_reference<T>::type&& constexpr_move(T&& t) noexcept +template <class T> +inline constexpr typename std::remove_reference<T>::type&& constexpr_move( + T&& t) noexcept { return static_cast<typename std::remove_reference<T>::type&&>(t); } - #if defined NDEBUG -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) +#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) #else -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR))) +#define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) \ + ((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR))) #endif - namespace detail_ { - // static_addressof: a constexpr version of addressof template <typename T> struct has_overloaded_addressof { - template <class X> - constexpr static bool has_overload(...) { return false; } - - template <class X, size_t S = sizeof(std::declval<X&>().operator&()) > - constexpr static bool has_overload(bool) { return true; } + template <class X> + constexpr static bool has_overload(...) + { + return false; + } + + template <class X, size_t S = sizeof(std::declval<X&>().operator&())> + constexpr static bool has_overload(bool) + { + return true; + } - constexpr static bool value = has_overload<T>(true); + constexpr static bool value = has_overload<T>(true); }; template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)> constexpr T* static_addressof(T& ref) { - return &ref; + return &ref; } template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)> T* static_addressof(T& ref) { - return std::addressof(ref); + return std::addressof(ref); } - -// the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A +// the call to convert<A>(b) has return type A and converts b to type A iff b +// decltype(b) is implicitly convertible to A template <class U> -constexpr U convert(U v) { return v; } - +constexpr U convert(U v) +{ + return v; +} namespace swap_ns { - using std::swap; - - template <class T> - void adl_swap(T& t, T& u) noexcept(noexcept(swap(t, u))) - { - swap(t, u); - } +using std::swap; -} // namespace swap_ns - -} // namespace detail +template <class T> +void adl_swap(T& t, T& u) noexcept(noexcept(swap(t, u))) +{ + swap(t, u); +} +} // namespace swap_ns -constexpr struct trivial_init_t{} trivial_init{}; +} // namespace detail_ +constexpr struct trivial_init_t +{ +} trivial_init{}; // 20.5.6, In-place construction -constexpr struct in_place_t{} in_place{}; - +constexpr struct in_place_t +{ +} in_place{}; // 20.5.7, Disengaged state indicator struct nullopt_t { - struct init{}; - constexpr explicit nullopt_t(init){} + struct init + { + }; + constexpr explicit nullopt_t(init) {} }; constexpr nullopt_t nullopt{nullopt_t::init()}; - // 20.5.8, class bad_optional_access -class bad_optional_access : public logic_error { +class bad_optional_access : public logic_error +{ public: - explicit bad_optional_access(const string& what_arg) : logic_error{what_arg} {} - explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {} + explicit bad_optional_access(const string& what_arg) : logic_error{what_arg} + { + } + explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} + { + } }; - template <class T> -union storage_t -{ - unsigned char dummy_; - T value_; +union storage_t { + unsigned char dummy_; + T value_; - constexpr storage_t( trivial_init_t ) noexcept : dummy_() {}; + constexpr storage_t(trivial_init_t) noexcept : dummy_(){}; - template <class... Args> - constexpr storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {} + template <class... Args> + constexpr storage_t(Args&&... args) : + value_(constexpr_forward<Args>(args)...) + { + } - ~storage_t(){} + ~storage_t() {} }; - template <class T> -union constexpr_storage_t -{ +union constexpr_storage_t { unsigned char dummy_; T value_; - constexpr constexpr_storage_t( trivial_init_t ) noexcept : dummy_() {}; + constexpr constexpr_storage_t(trivial_init_t) noexcept : dummy_(){}; template <class... Args> - constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {} + constexpr constexpr_storage_t(Args&&... args) : + value_(constexpr_forward<Args>(args)...) + { + } ~constexpr_storage_t() = default; }; - template <class T> struct optional_base { bool init_; storage_t<T> storage_; - constexpr optional_base() noexcept : init_(false), storage_(trivial_init) {}; + constexpr optional_base() noexcept : init_(false), storage_(trivial_init){}; explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {} - explicit constexpr optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} + explicit constexpr optional_base(T&& v) : + init_(true), storage_(constexpr_move(v)) + { + } - template <class... Args> explicit optional_base(in_place_t, Args&&... args) - : init_(true), storage_(constexpr_forward<Args>(args)...) {} + template <class... Args> + explicit optional_base(in_place_t, Args&&... args) : + init_(true), storage_(constexpr_forward<Args>(args)...) + { + } - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> - explicit optional_base(in_place_t, std::initializer_list<U> il, Args&&... args) - : init_(true), storage_(il, std::forward<Args>(args)...) {} + template < + class U, class... Args, + TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U> >)> + explicit optional_base( + in_place_t, std::initializer_list<U> il, Args&&... args) : + init_(true), + storage_(il, std::forward<Args>(args)...) + { + } - ~optional_base() { if (init_) storage_.value_.T::~T(); } + ~optional_base() + { + if (init_) + storage_.value_.T::~T(); + } }; - template <class T> struct constexpr_optional_base { bool init_; constexpr_storage_t<T> storage_; - constexpr constexpr_optional_base() noexcept : init_(false), storage_(trivial_init) {}; + constexpr constexpr_optional_base() noexcept : init_(false), + storage_(trivial_init){}; - explicit constexpr constexpr_optional_base(const T& v) : init_(true), storage_(v) {} + explicit constexpr constexpr_optional_base(const T& v) : + init_(true), storage_(v) + { + } - explicit constexpr constexpr_optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {} + explicit constexpr constexpr_optional_base(T&& v) : + init_(true), storage_(constexpr_move(v)) + { + } - template <class... Args> explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) - : init_(true), storage_(constexpr_forward<Args>(args)...) {} + template <class... Args> + explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) : + init_(true), storage_(constexpr_forward<Args>(args)...) + { + } - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, std::initializer_list<U> il, Args&&... args) - : init_(true), storage_(il, std::forward<Args>(args)...) {} + template < + class U, class... Args, + TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U> >)> + OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base( + in_place_t, std::initializer_list<U> il, Args&&... args) : + init_(true), + storage_(il, std::forward<Args>(args)...) + { + } ~constexpr_optional_base() = default; }; template <class T> using OptionalBase = typename std::conditional< - is_trivially_destructible<T>::value, // if possible - constexpr_optional_base<typename std::remove_const<T>::type>, // use base with trivial destructor - optional_base<typename std::remove_const<T>::type> ->::type; - - + is_trivially_destructible<T>::value, // if possible + constexpr_optional_base<typename std::remove_const< + T>::type>, // use base with trivial destructor + optional_base<typename std::remove_const<T>::type> >::type; template <class T> class optional : private OptionalBase<T> { - static_assert( !std::is_same<typename std::decay<T>::type, nullopt_t>::value, "bad T" ); - static_assert( !std::is_same<typename std::decay<T>::type, in_place_t>::value, "bad T" ); - - - constexpr bool initialized() const noexcept { return OptionalBase<T>::init_; } - typename std::remove_const<T>::type* dataptr() { return std::addressof(OptionalBase<T>::storage_.value_); } - constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase<T>::storage_.value_); } - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - constexpr const T& contained_val() const& { return OptionalBase<T>::storage_.value_; } -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); } - OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase<T>::storage_.value_; } -# else - T& contained_val() & { return OptionalBase<T>::storage_.value_; } - T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); } -# endif -# else - constexpr const T& contained_val() const { return OptionalBase<T>::storage_.value_; } - T& contained_val() { return OptionalBase<T>::storage_.value_; } -# endif - - void clear() noexcept { - if (initialized()) dataptr()->T::~T(); - OptionalBase<T>::init_ = false; - } - - template <class... Args> - void initialize(Args&&... args) noexcept(noexcept(T(std::forward<Args>(args)...))) - { - assert(!OptionalBase<T>::init_); - ::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...); - OptionalBase<T>::init_ = true; - } - - template <class U, class... Args> - void initialize(std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, std::forward<Args>(args)...))) - { - assert(!OptionalBase<T>::init_); - ::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...); - OptionalBase<T>::init_ = true; - } + static_assert( + !std::is_same<typename std::decay<T>::type, nullopt_t>::value, "bad T"); + static_assert( + !std::is_same<typename std::decay<T>::type, in_place_t>::value, + "bad T"); -public: - typedef T value_type; + constexpr bool initialized() const noexcept + { + return OptionalBase<T>::init_; + } + typename std::remove_const<T>::type* dataptr() + { + return std::addressof(OptionalBase<T>::storage_.value_); + } + constexpr const T* dataptr() const + { + return detail_::static_addressof(OptionalBase<T>::storage_.value_); + } + +#if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 + constexpr const T& contained_val() const& + { + return OptionalBase<T>::storage_.value_; + } +#if OPTIONAL_HAS_MOVE_ACCESSORS == 1 + OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && + { + return std::move(OptionalBase<T>::storage_.value_); + } + OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & + { + return OptionalBase<T>::storage_.value_; + } +#else + T& contained_val() & { return OptionalBase<T>::storage_.value_; } + T&& contained_val() && + { + return std::move(OptionalBase<T>::storage_.value_); + } +#endif +#else + constexpr const T& contained_val() const + { + return OptionalBase<T>::storage_.value_; + } + T& contained_val() { return OptionalBase<T>::storage_.value_; } +#endif - // 20.5.5.1, constructors - constexpr optional() noexcept : OptionalBase<T>() {}; - constexpr optional(nullopt_t) noexcept : OptionalBase<T>() {}; + void clear() noexcept + { + if (initialized()) + dataptr()->T::~T(); + OptionalBase<T>::init_ = false; + } - optional(const optional& rhs) - : OptionalBase<T>() - { - if (rhs.initialized()) { - ::new (static_cast<void*>(dataptr())) T(*rhs); + template <class... Args> + void initialize(Args&&... args) + noexcept(noexcept(T(std::forward<Args>(args)...))) + { + assert(!OptionalBase<T>::init_); + ::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...); OptionalBase<T>::init_ = true; } - } - optional(optional&& rhs) noexcept(is_nothrow_move_constructible<T>::value) - : OptionalBase<T>() - { - if (rhs.initialized()) { - ::new (static_cast<void*>(dataptr())) T(std::move(*rhs)); + template <class U, class... Args> + void initialize(std::initializer_list<U> il, Args&&... args) + noexcept(noexcept(T(il, std::forward<Args>(args)...))) + { + assert(!OptionalBase<T>::init_); + ::new (static_cast<void*>(dataptr())) + T(il, std::forward<Args>(args)...); OptionalBase<T>::init_ = true; } - } - - constexpr optional(const T& v) : OptionalBase<T>(v) {} - - constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {} - - template <class... Args> - explicit constexpr optional(in_place_t, Args&&... args) - : OptionalBase<T>(in_place_t{}, constexpr_forward<Args>(args)...) {} - - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(is_constructible<T, std::initializer_list<U>>)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, std::initializer_list<U> il, Args&&... args) - : OptionalBase<T>(in_place_t{}, il, constexpr_forward<Args>(args)...) {} - - // 20.5.4.2, Destructor - ~optional() = default; - - // 20.5.4.3, assignment - optional& operator=(nullopt_t) noexcept - { - clear(); - return *this; - } - - optional& operator=(const optional& rhs) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); - else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; - return *this; - } - - optional& operator=(optional&& rhs) - noexcept(is_nothrow_move_assignable<T>::value && is_nothrow_move_constructible<T>::value) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(std::move(*rhs)); - else if (initialized() == true && rhs.initialized() == true) contained_val() = std::move(*rhs); - return *this; - } - - template <class U> - auto operator=(U&& v) - -> typename enable_if - < - is_same<typename decay<U>::type, T>::value, - optional& - >::type - { - if (initialized()) { contained_val() = std::forward<U>(v); } - el |