Created
August 11, 2016 07:14
-
-
Save EricWF/f6ae31ab465075bcb6b8a7f86e313075 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //===----------------------------------------------------------------------===// | |
| // | |
| // The LLVM Compiler Infrastructure | |
| // | |
| // This file is dual licensed under the MIT and the University of Illinois Open | |
| // Source Licenses. See LICENSE.TXT for details. | |
| // | |
| //===----------------------------------------------------------------------===// | |
| // UNSUPPORTED: c++98, c++03, c++11, c++14 | |
| // <optional> | |
| #include <optional> | |
| #include <type_traits> | |
| #include <cassert> | |
| #include "archetypes.hpp" | |
| template <class T> | |
| struct SpecialMemberTest { | |
| using O = std::optional<T>; | |
| template <template <class> class TestMF> | |
| static constexpr bool check_same() { | |
| return TestMF<T>::value == TestMF<O>::value; | |
| } | |
| template <template <class> class CopyMF, | |
| template <class> class MoveMF | |
| > | |
| static constexpr bool check_copy_move() { | |
| static_assert(CopyMF<T>::value == CopyMF<O>::value, ""); | |
| constexpr bool ExpectMove = CopyMF<T>::value || MoveMF<T>::value; | |
| return ExpectMove == MoveMF<O>::value; | |
| } | |
| static_assert(std::is_default_constructible<O>::value, | |
| "optional is always default constructible"); | |
| static_assert(check_copy_move<std::is_copy_constructible, | |
| std::is_move_constructible>(), ""); | |
| static_assert(check_copy_move<std::is_copy_assignable, | |
| std::is_move_assignable>(), ""); | |
| // Test that optional inherits the correct trivial/non-trivial members | |
| static_assert(check_same<std::is_trivially_destructible>(), ""); | |
| static_assert(check_same<std::is_trivially_copyable>(), ""); | |
| // These tests below may be incorrect yet. | |
| static_assert(check_same<std::is_trivially_copy_constructible>(), ""); | |
| static_assert(check_same<std::is_trivially_move_constructible>(), ""); | |
| }; | |
| template <class ...TestTypes> | |
| struct DoTestsMetafunction { | |
| template <class ...Args> static void sink(Args...) {} | |
| DoTestsMetafunction() { sink(SpecialMemberTest<TestTypes>{}...); } | |
| }; | |
| ImplicitTypes::ApplyTypes<DoTestsMetafunction> do_test_anchor1; | |
| ExplicitTypes::ApplyTypes<DoTestsMetafunction> do_test_anchor2; | |
| NonLiteralTypes::ApplyTypes<DoTestsMetafunction> do_test_anchor3; | |
| NonTrivialTypes::ApplyTypes<DoTestsMetafunction> do_test_anchor4; | |
| int main() | |
| { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment