Skip to content

Commit

Permalink
Example conversion for optional, using [[trivially_relocatable]].
Browse files Browse the repository at this point in the history
  • Loading branch information
Quuxplusone committed Nov 19, 2018
1 parent 999b73a commit ccae878
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions include/__config
Expand Up @@ -1281,6 +1281,14 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
#define _LIBCPP_HAS_NO_IS_AGGREGATE #define _LIBCPP_HAS_NO_IS_AGGREGATE
#endif #endif


#ifndef _LIBCPP_TRIVIALLY_RELOCATABLE
#if __has_extension(trivially_relocatable)
#define _LIBCPP_TRIVIALLY_RELOCATABLE [[clang::trivially_relocatable]]
#else
#define _LIBCPP_TRIVIALLY_RELOCATABLE
#endif
#endif

#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L #if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
#define _LIBCPP_HAS_NO_COROUTINES #define _LIBCPP_HAS_NO_COROUTINES
#endif #endif
Expand Down
16 changes: 14 additions & 2 deletions include/optional
Expand Up @@ -580,13 +580,25 @@ using __optional_sfinae_assign_base_t = __sfinae_assign_base<
(is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value) (is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)
>; >;


template <class _Tp, bool = is_trivially_relocatable<_Tp>::value>
struct __optional_relocate_base : __optional_move_assign_base<_Tp>
{
using __optional_move_assign_base<_Tp>::__optional_move_assign_base;
};

template <class _Tp>
struct _LIBCPP_TRIVIALLY_RELOCATABLE __optional_relocate_base<_Tp, true> : __optional_move_assign_base<_Tp>
{
using __optional_move_assign_base<_Tp>::__optional_move_assign_base;
};

template <class _Tp> template <class _Tp>
class optional class optional
: private __optional_move_assign_base<_Tp> : private __optional_relocate_base<_Tp>
, private __optional_sfinae_ctor_base_t<_Tp> , private __optional_sfinae_ctor_base_t<_Tp>
, private __optional_sfinae_assign_base_t<_Tp> , private __optional_sfinae_assign_base_t<_Tp>
{ {
using __base = __optional_move_assign_base<_Tp>; using __base = __optional_relocate_base<_Tp>;
public: public:
using value_type = _Tp; using value_type = _Tp;


Expand Down

0 comments on commit ccae878

Please sign in to comment.