From e59cf7b09e7388d369e8d2bf73501cde79c28708 Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 8 Apr 2021 16:43:58 +0200 Subject: Squashed 'EASTL/' content from commit fad5471 git-subtree-dir: EASTL git-subtree-split: fad54717f8e4ebb13b20095da7efd07a53af0f10 --- test/source/ConceptImpls.h | 192 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 test/source/ConceptImpls.h (limited to 'test/source/ConceptImpls.h') diff --git a/test/source/ConceptImpls.h b/test/source/ConceptImpls.h new file mode 100644 index 0000000..e6c20ef --- /dev/null +++ b/test/source/ConceptImpls.h @@ -0,0 +1,192 @@ +///////////////////////////////////////////////////////////////////////////// +// Copyright (c) Electronic Arts Inc. All rights reserved. +///////////////////////////////////////////////////////////////////////////// + +#ifndef CONCEPTSIMPLS_H +#define CONCEPTSIMPLS_H + +#include + +#if !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS) + +#define EASTL_TEST_CONCEPT_IMPLS + +// This header provides a variety of helper classes that have interfaces corresponding to the concepts used to specify +// requirements of many STL containers and algorithms. These helper classes are used in tests to verify that containers +// and algorithms do not impose stricter requirements than specified by the standard on their arguments. + +// Destructible - only valid operation on this class is to destroy it. + +class Destructible +{ +public: + ~Destructible() = default; + + Destructible() = delete; + Destructible(const Destructible&) = delete; + Destructible(Destructible&&) = delete; + Destructible& operator=(const Destructible&) = delete; + Destructible& operator=(Destructible&&) = delete; +}; + +// Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly +// static_assert everything that should be true of this class +static_assert(eastl::is_destructible::value, "eastl::is_destructible::value"); +// static_assert(!eastl::is_default_constructible::value, +// "!eastl::is_default_constructible::value"); +// static_assert(!is_copy_constructible::value, "!eastl::is_copy_constructible::value"); +static_assert(!eastl::is_copy_assignable::value, "!eastl::is_copy_assignable::value"); +// static_assert(!eastl::is_move_constructible::value, +// "!eastl::is_move_constructible::value"); +static_assert(!eastl::is_move_assignable::value, "!eastl::is_move_assignable::value"); + +class DefaultConstructible +{ +public: + static const int defaultValue = 42; + + DefaultConstructible() : value(defaultValue) {} + ~DefaultConstructible() = default; + + DefaultConstructible(const DefaultConstructible&) = delete; + DefaultConstructible(DefaultConstructible&&) = delete; + DefaultConstructible& operator=(const DefaultConstructible&) = delete; + DefaultConstructible& operator=(DefaultConstructible&&) = delete; + + const int value; +}; + + +struct NotDefaultConstructible +{ + NotDefaultConstructible() = delete; +}; +static_assert(!eastl::is_default_constructible::value, "'NotDefaultConstructible' is default constructible."); + + +class CopyConstructible +{ +public: + static const int defaultValue = 42; + static CopyConstructible Create() + { + CopyConstructible x; + return x; + } + + CopyConstructible(const CopyConstructible&) = default; + ~CopyConstructible() = default; + + CopyConstructible& operator=(const CopyConstructible&) = delete; + CopyConstructible& operator=(CopyConstructible&&) = delete; + + const int value; + +private: + CopyConstructible() : value(defaultValue) {} +}; + +// Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly +// static_assert everything that should be true of this class +static_assert(eastl::is_destructible::value, "eastl::is_destructible::value"); +// static_assert(!eastl::is_default_constructible::value, +// "!eastl::is_default_constructible::value"); +// static_assert(is_copy_constructible::value, "is_copy_constructible::value"); +static_assert(eastl::is_copy_constructible::value, + "eastl::is_copy_constructible::value"); +static_assert(!eastl::is_copy_assignable::value, + "!eastl::is_copy_assignable::value"); +// static_assert(!eastl::is_move_constructible::value, +// "!eastl::is_move_constructible::value"); +static_assert(!eastl::is_move_assignable::value, + "!eastl::is_move_assignable::value"); + +class MoveConstructible +{ +public: + static const int defaultValue = 42; + static MoveConstructible Create() + { + return MoveConstructible{}; + } + + MoveConstructible(MoveConstructible&& x) : value(x.value) {} + ~MoveConstructible() = default; + + MoveConstructible(const MoveConstructible&) = delete; + MoveConstructible& operator=(const MoveConstructible&) = delete; + MoveConstructible& operator=(MoveConstructible&&) = delete; + + const int value; + +private: + MoveConstructible() : value(defaultValue) {} +}; + +class MoveAssignable +{ +public: + static const int defaultValue = 42; + static MoveAssignable Create() + { + return MoveAssignable{}; + } + + MoveAssignable(MoveAssignable&& x) : value(x.value) {} + MoveAssignable& operator=(MoveAssignable&& x) + { + value = x.value; + return *this; + } + ~MoveAssignable() = default; + + MoveAssignable(const MoveAssignable&) = delete; + MoveAssignable& operator=(const MoveAssignable&) = delete; + + int value; + +private: + MoveAssignable() : value(defaultValue) {} +}; + +struct MoveAndDefaultConstructible +{ + static const int defaultValue = 42; + + MoveAndDefaultConstructible() : value(defaultValue) {} + MoveAndDefaultConstructible(MoveAndDefaultConstructible&& x) : value(x.value) {} + ~MoveAndDefaultConstructible() = default; + + MoveAndDefaultConstructible(const MoveAndDefaultConstructible&) = delete; + MoveAndDefaultConstructible& operator=(const MoveAndDefaultConstructible&) = delete; + MoveAndDefaultConstructible& operator=(MoveAndDefaultConstructible&&) = delete; + + const int value; +}; + +struct MissingMoveConstructor +{ + MissingMoveConstructor() {} + MissingMoveConstructor(const MissingMoveConstructor&) {} + MissingMoveConstructor& operator=(MissingMoveConstructor&&) { return *this; } + MissingMoveConstructor& operator=(const MissingMoveConstructor&) { return *this; } + bool operator<(const MissingMoveConstructor&) const { return true; } +}; + +struct MissingMoveAssignable +{ + MissingMoveAssignable() {} + MissingMoveAssignable(const MissingMoveAssignable&) {} + MissingMoveAssignable(MissingMoveAssignable&&) {} + MissingMoveAssignable& operator=(const MissingMoveAssignable&) { return *this; } + bool operator<(const MissingMoveAssignable&) const { return true; } +}; + +struct MissingEquality +{ + MissingEquality& operator==(const MissingEquality&) = delete; +}; + +#endif // !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS) + +#endif // CONCEPTSIMPLS_H -- cgit v1.2.3