Skip to content

Commit

Permalink
Add <experimental/memory_resource>
Browse files Browse the repository at this point in the history
Reviewers: mclow.lists, EricWF

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D20007

llvm-svn: 268829
  • Loading branch information
EricWF committed May 7, 2016
1 parent 7fa7dc3 commit 15551ef
Show file tree
Hide file tree
Showing 55 changed files with 4,712 additions and 6 deletions.
19 changes: 19 additions & 0 deletions libcxx/include/exception
Expand Up @@ -80,6 +80,10 @@ template <class E> void rethrow_if_nested(const E& e);
#include <__config>
#include <cstddef>
#include <type_traits>
#if defined(_LIBCPP_HAS_NO_EXCEPTIONS)
#include <cstdio>
#include <cstdlib>
#endif

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
Expand Down Expand Up @@ -251,4 +255,19 @@ rethrow_if_nested(const _Ep&, typename enable_if<

} // std

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Exception>
_LIBCPP_INLINE_VISIBILITY
inline void __libcpp_throw(_Exception const& __e) {
#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
throw __e;
#else
_VSTD::fprintf(stderr, "%s\n", __e.what());
_VSTD::abort();
#endif
}

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP_EXCEPTION
4 changes: 4 additions & 0 deletions libcxx/include/experimental/__config
Expand Up @@ -25,6 +25,10 @@
#define _LIBCPP_END_NAMESPACE_LFTS } } }
#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1

#define _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR _LIBCPP_BEGIN_NAMESPACE_LFTS namespace pmr {
#define _LIBCPP_END_NAMESPACE_LFTS_PMR _LIBCPP_END_NAMESPACE_LFTS }
#define _VSTD_LFTS_PMR _VSTD_LFTS::pmr

#define _LIBCPP_BEGIN_NAMESPACE_CHRONO_LFTS _LIBCPP_BEGIN_NAMESPACE_STD \
namespace chrono { namespace experimental { inline namespace fundamentals_v1 {
#define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } }
Expand Down
90 changes: 90 additions & 0 deletions libcxx/include/experimental/__memory
@@ -0,0 +1,90 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_EXPERIMENTAL___MEMORY
#define _LIBCPP_EXPERIMENTAL___MEMORY

#include <experimental/__config>
#include <experimental/utility> // for erased_type
#include <__functional_base>
#include <type_traits>

_LIBCPP_BEGIN_NAMESPACE_LFTS

template <
class _Tp, class _Alloc
, bool = uses_allocator<_Tp, _Alloc>::value
, bool = __has_allocator_type<_Tp>::value
>
struct __lfts_uses_allocator : public false_type {};

template <class _Tp, class _Alloc>
struct __lfts_uses_allocator<_Tp, _Alloc, false, false> : public false_type {};

template <class _Tp, class _Alloc, bool HasAlloc>
struct __lfts_uses_allocator<_Tp, _Alloc, true, HasAlloc> : public true_type {};

template <class _Tp, class _Alloc>
struct __lfts_uses_allocator<_Tp, _Alloc, false, true>
: public integral_constant<bool
, is_convertible<_Alloc, typename _Tp::allocator_type>::value
|| is_same<erased_type, typename _Tp::allocator_type>::value
>
{};

template <bool _UsesAlloc, class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor_imp
{
static const int value = 0;
};

template <class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor_imp<true, _Tp, _Alloc, _Args...>
{
static const bool __ic_first
= is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;

static const bool __ic_second =
conditional<
__ic_first,
false_type,
is_constructible<_Tp, _Args..., _Alloc>
>::type::value;

static_assert(__ic_first || __ic_second,
"Request for uses allocator construction is ill-formed");

static const int value = __ic_first ? 1 : 2;
};

template <class _Tp, class _Alloc, class ..._Args>
struct __lfts_uses_alloc_ctor
: integral_constant<int,
__lfts_uses_alloc_ctor_imp<
__lfts_uses_allocator<_Tp, _Alloc>::value
, _Tp, _Alloc, _Args...
>::value
>
{};

template <class _Tp, class _Alloc, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
void __lfts_user_alloc_construct(
_Tp * __store, const _Alloc & __a, _Args &&... __args)
{
_VSTD::__user_alloc_construct_impl(
typename __lfts_uses_alloc_ctor<_Tp, _Alloc, _Args...>::type()
, __store, __a, _VSTD::forward<_Args>(__args)...
);
}

_LIBCPP_END_NAMESPACE_LFTS

#endif /* _LIBCPP_EXPERIMENTAL___MEMORY */

0 comments on commit 15551ef

Please sign in to comment.