Vendor import of libc++ trunk r305575:
https://llvm.org/svn/llvm-project/libcxx/trunk@305575
This commit is contained in:
parent
25e9344f14
commit
37ec3a3c04
38
benchmarks/stringstream.bench.cpp
Normal file
38
benchmarks/stringstream.bench.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "benchmark/benchmark_api.h"
|
||||
|
||||
#include <sstream>
|
||||
double __attribute__((noinline)) istream_numbers();
|
||||
|
||||
double istream_numbers() {
|
||||
const char *a[] = {
|
||||
"-6 69 -71 2.4882e-02 -100 101 -2.00005 5000000 -50000000",
|
||||
"-25 71 7 -9.3262e+01 -100 101 -2.00005 5000000 -50000000",
|
||||
"-14 53 46 -6.7026e-02 -100 101 -2.00005 5000000 -50000000"
|
||||
};
|
||||
|
||||
int a1, a2, a3, a4, a5, a6, a7;
|
||||
double f1 = 0.0, f2 = 0.0, q = 0.0;
|
||||
for (int i=0; i < 3; i++) {
|
||||
std::istringstream s(a[i]);
|
||||
s >> a1
|
||||
>> a2
|
||||
>> a3
|
||||
>> f1
|
||||
>> a4
|
||||
>> a5
|
||||
>> f2
|
||||
>> a6
|
||||
>> a7;
|
||||
q += (a1 + a2 + a3 + a4 + a5 + a6 + a7 + f1 + f2)/1000000;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
static void BM_Istream_numbers(benchmark::State &state) {
|
||||
double i = 0;
|
||||
while (state.KeepRunning())
|
||||
benchmark::DoNotOptimize(i += istream_numbers());
|
||||
}
|
||||
|
||||
BENCHMARK(BM_Istream_numbers)->RangeMultiplier(2)->Range(1024, 4096);
|
||||
BENCHMARK_MAIN()
|
@ -15,6 +15,7 @@
|
||||
#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <memory>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
@ -76,6 +76,9 @@
|
||||
// its vtable and typeinfo to libc++ rather than having all other libraries
|
||||
// using that class define their own copies.
|
||||
#define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
|
||||
|
||||
// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
|
||||
#define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
#elif _LIBCPP_ABI_VERSION == 1
|
||||
#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
|
||||
// Enable compiling copies of now inline methods into the dylib to support
|
||||
@ -289,7 +292,7 @@
|
||||
# endif
|
||||
#endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN)
|
||||
|
||||
#if __has_attribute(__no_sanitize__)
|
||||
#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
|
||||
#define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
|
||||
#else
|
||||
#define _LIBCPP_NO_CFI
|
||||
@ -1132,8 +1135,6 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
|
||||
# define _LIBCPP_HAS_NO_COROUTINES
|
||||
#endif
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
// Decide whether to use availability macros.
|
||||
#if !defined(_LIBCPP_BUILDING_LIBRARY) && \
|
||||
!defined(_LIBCPP_DISABLE_AVAILABILITY) && \
|
||||
@ -1237,4 +1238,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
|
||||
# endif
|
||||
#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
|
||||
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // _LIBCPP_CONFIG
|
||||
|
@ -704,7 +704,7 @@ function<_Rp()>::target()
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (_Tp*)0;
|
||||
return (_Tp*)__f_->target(typeid(_Tp));
|
||||
return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
|
||||
}
|
||||
|
||||
template<class _Rp>
|
||||
@ -980,7 +980,7 @@ function<_Rp(_A0)>::target()
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (_Tp*)0;
|
||||
return (_Tp*)__f_->target(typeid(_Tp));
|
||||
return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
|
||||
}
|
||||
|
||||
template<class _Rp, class _A0>
|
||||
@ -1256,7 +1256,7 @@ function<_Rp(_A0, _A1)>::target()
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (_Tp*)0;
|
||||
return (_Tp*)__f_->target(typeid(_Tp));
|
||||
return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
|
||||
}
|
||||
|
||||
template<class _Rp, class _A0, class _A1>
|
||||
@ -1532,7 +1532,7 @@ function<_Rp(_A0, _A1, _A2)>::target()
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (_Tp*)0;
|
||||
return (_Tp*)__f_->target(typeid(_Tp));
|
||||
return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
|
||||
}
|
||||
|
||||
template<class _Rp, class _A0, class _A1, class _A2>
|
||||
|
@ -548,16 +548,13 @@ template <class _Tp> void cref(const _Tp&&) = delete;
|
||||
#endif
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
template <class _Tp1, class _Tp2 = void>
|
||||
struct __is_transparent
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp1>(0)) == 1;
|
||||
};
|
||||
template <class _Tp, class, class = void>
|
||||
struct __is_transparent : false_type {};
|
||||
|
||||
template <class _Tp, class _Up>
|
||||
struct __is_transparent<_Tp, _Up,
|
||||
typename __void_t<typename _Tp::is_transparent>::type>
|
||||
: true_type {};
|
||||
#endif
|
||||
|
||||
// allocator_arg_t
|
||||
|
@ -296,6 +296,7 @@ class _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
|
||||
template <size_t _Ip, class _Tp, size_t _Size>
|
||||
class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
|
||||
{
|
||||
static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
|
||||
public:
|
||||
typedef _Tp type;
|
||||
};
|
||||
|
@ -250,9 +250,11 @@ public:
|
||||
|
||||
_LIBCPP_ALWAYS_INLINE
|
||||
static coroutine_handle from_promise(_Promise& __promise) _NOEXCEPT {
|
||||
typedef typename remove_cv<_Promise>::type _RawPromise;
|
||||
coroutine_handle __tmp;
|
||||
__tmp.__handle_ = __builtin_coro_promise(_VSTD::addressof(__promise),
|
||||
__alignof(_Promise), true);
|
||||
__tmp.__handle_ = __builtin_coro_promise(
|
||||
_VSTD::addressof(const_cast<_RawPromise&>(__promise)),
|
||||
__alignof(_Promise), true);
|
||||
return __tmp;
|
||||
}
|
||||
};
|
||||
|
@ -617,7 +617,7 @@ basic_filebuf<_CharT, _Traits>::underflow()
|
||||
static_cast<size_t>(__extbufend_ - __extbufnext_));
|
||||
codecvt_base::result __r;
|
||||
__st_last_ = __st_;
|
||||
size_t __nr = fread((void*)__extbufnext_, 1, __nmemb, __file_);
|
||||
size_t __nr = fread((void*) const_cast<char *>(__extbufnext_), 1, __nmemb, __file_);
|
||||
if (__nr != 0)
|
||||
{
|
||||
if (!__cv_)
|
||||
@ -630,7 +630,8 @@ basic_filebuf<_CharT, _Traits>::underflow()
|
||||
this->eback() + __ibs_, __inext);
|
||||
if (__r == codecvt_base::noconv)
|
||||
{
|
||||
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_);
|
||||
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
|
||||
(char_type*)const_cast<char *>(__extbufend_));
|
||||
__c = traits_type::to_int_type(*this->gptr());
|
||||
}
|
||||
else if (__inext != this->eback() + __unget_sz)
|
||||
@ -722,7 +723,7 @@ basic_filebuf<_CharT, _Traits>::overflow(int_type __c)
|
||||
return traits_type::eof();
|
||||
if (__r == codecvt_base::partial)
|
||||
{
|
||||
this->setp((char_type*)__e, this->pptr());
|
||||
this->setp(const_cast<char_type*>(__e), this->pptr());
|
||||
this->pbump(this->epptr() - this->pbase());
|
||||
}
|
||||
}
|
||||
|
@ -1941,8 +1941,8 @@ _Tp*
|
||||
function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (_Tp*)0;
|
||||
return (_Tp*)__f_->target(typeid(_Tp));
|
||||
return nullptr;
|
||||
return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
|
||||
}
|
||||
|
||||
template<class _Rp, class ..._ArgTypes>
|
||||
@ -1951,7 +1951,7 @@ const _Tp*
|
||||
function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
|
||||
{
|
||||
if (__f_ == 0)
|
||||
return (const _Tp*)0;
|
||||
return nullptr;
|
||||
return (const _Tp*)__f_->target(typeid(_Tp));
|
||||
}
|
||||
|
||||
|
@ -372,19 +372,57 @@ template <class _CharT>
|
||||
struct __num_get
|
||||
: protected __num_get_base
|
||||
{
|
||||
static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
|
||||
static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
|
||||
_CharT& __thousands_sep);
|
||||
static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
|
||||
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
|
||||
unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
|
||||
|
||||
static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
|
||||
char* __a, char*& __a_end,
|
||||
_CharT __decimal_point, _CharT __thousands_sep,
|
||||
const string& __grouping, unsigned* __g,
|
||||
unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
|
||||
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
|
||||
static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
|
||||
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
|
||||
unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
|
||||
|
||||
#else
|
||||
static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
|
||||
{
|
||||
locale __loc = __iob.getloc();
|
||||
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
|
||||
__thousands_sep = __np.thousands_sep();
|
||||
return __np.grouping();
|
||||
}
|
||||
|
||||
const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
|
||||
{
|
||||
return __do_widen_p(__iob, __atoms);
|
||||
}
|
||||
|
||||
|
||||
static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
|
||||
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
|
||||
unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
|
||||
private:
|
||||
template<typename T>
|
||||
const T* __do_widen_p(ios_base& __iob, T* __atoms) const
|
||||
{
|
||||
locale __loc = __iob.getloc();
|
||||
use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms);
|
||||
return __atoms;
|
||||
}
|
||||
|
||||
const char* __do_widen_p(ios_base& __iob, char* __atoms) const
|
||||
{
|
||||
(void)__iob;
|
||||
(void)__atoms;
|
||||
return __src;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
template <class _CharT>
|
||||
string
|
||||
__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
|
||||
@ -395,6 +433,7 @@ __num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& _
|
||||
__thousands_sep = __np.thousands_sep();
|
||||
return __np.grouping();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class _CharT>
|
||||
string
|
||||
@ -411,9 +450,16 @@ __num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT&
|
||||
|
||||
template <class _CharT>
|
||||
int
|
||||
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
|
||||
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
|
||||
unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
|
||||
#else
|
||||
__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
|
||||
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
|
||||
unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
|
||||
|
||||
#endif
|
||||
{
|
||||
if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
|
||||
{
|
||||
@ -849,9 +895,16 @@ num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
|
||||
// Stage 1
|
||||
int __base = this->__get_base(__iob);
|
||||
// Stage 2
|
||||
char_type __atoms[26];
|
||||
char_type __thousands_sep;
|
||||
const int __atoms_size = 26;
|
||||
#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
char_type __atoms1[__atoms_size];
|
||||
const char_type *__atoms = this->__do_widen(__iob, __atoms1);
|
||||
string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
|
||||
#else
|
||||
char_type __atoms[__atoms_size];
|
||||
string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
|
||||
#endif
|
||||
string __buf;
|
||||
__buf.resize(__buf.capacity());
|
||||
char* __a = &__buf[0];
|
||||
@ -899,9 +952,16 @@ num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e,
|
||||
// Stage 1
|
||||
int __base = this->__get_base(__iob);
|
||||
// Stage 2
|
||||
char_type __atoms[26];
|
||||
char_type __thousands_sep;
|
||||
const int __atoms_size = 26;
|
||||
#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
|
||||
char_type __atoms1[__atoms_size];
|
||||
const char_type *__atoms = this->__do_widen(__iob, __atoms1);
|
||||
string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
|
||||
#else
|
||||
char_type __atoms[__atoms_size];
|
||||
string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
|
||||
#endif
|
||||
string __buf;
|
||||
__buf.resize(__buf.capacity());
|
||||
char* __a = &__buf[0];
|
||||
@ -3960,7 +4020,8 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
|
||||
this->egptr(), __inext);
|
||||
if (__r == codecvt_base::noconv)
|
||||
{
|
||||
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)__extbufend_);
|
||||
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
|
||||
(char_type*) const_cast<char *>(__extbufend_));
|
||||
__c = *this->gptr();
|
||||
}
|
||||
else if (__inext != this->eback() + __unget_sz)
|
||||
@ -4048,7 +4109,7 @@ wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
|
||||
return traits_type::eof();
|
||||
if (__r == codecvt_base::partial)
|
||||
{
|
||||
this->setp((char_type*)__e, this->pptr());
|
||||
this->setp(const_cast<char_type *>(__e), this->pptr());
|
||||
this->pbump(this->epptr() - this->pbase());
|
||||
}
|
||||
}
|
||||
|
177
include/memory
177
include/memory
@ -720,16 +720,12 @@ public:
|
||||
|
||||
// pointer_traits
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_element_type : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_element_type
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::element_type* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_element_type<_Tp,
|
||||
typename __void_t<typename _Tp::element_type>::type> : true_type {};
|
||||
|
||||
template <class _Ptr, bool = __has_element_type<_Ptr>::value>
|
||||
struct __pointer_traits_element_type;
|
||||
@ -808,16 +804,12 @@ struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
|
||||
|
||||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_difference_type : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_difference_type
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::difference_type* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_difference_type<_Tp,
|
||||
typename __void_t<typename _Tp::difference_type>::type> : true_type {};
|
||||
|
||||
template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
|
||||
struct __pointer_traits_difference_type
|
||||
@ -998,17 +990,12 @@ struct __rebind_pointer {
|
||||
|
||||
// allocator_traits
|
||||
|
||||
struct __has_pointer_type_imp
|
||||
{
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::pointer* = 0);
|
||||
};
|
||||
template <class _Tp, class = void>
|
||||
struct __has_pointer_type : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_pointer_type
|
||||
: public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
|
||||
{
|
||||
};
|
||||
struct __has_pointer_type<_Tp,
|
||||
typename __void_t<typename _Tp::pointer>::type> : true_type {};
|
||||
|
||||
namespace __pointer_type_imp
|
||||
{
|
||||
@ -1033,16 +1020,12 @@ struct __pointer_type
|
||||
typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_const_pointer : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_const_pointer
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::const_pointer* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_const_pointer<_Tp,
|
||||
typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
|
||||
|
||||
template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
|
||||
struct __const_pointer
|
||||
@ -1060,16 +1043,12 @@ struct __const_pointer<_Tp, _Ptr, _Alloc, false>
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_void_pointer : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_void_pointer
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::void_pointer* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_void_pointer<_Tp,
|
||||
typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
|
||||
|
||||
template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
|
||||
struct __void_pointer
|
||||
@ -1087,16 +1066,12 @@ struct __void_pointer<_Ptr, _Alloc, false>
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_const_void_pointer : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_const_void_pointer
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_const_void_pointer<_Tp,
|
||||
typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
|
||||
|
||||
template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
|
||||
struct __const_void_pointer
|
||||
@ -1130,16 +1105,12 @@ __to_raw_pointer(_Pointer __p) _NOEXCEPT
|
||||
return _VSTD::__to_raw_pointer(__p.operator->());
|
||||
}
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_size_type : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_size_type
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::size_type* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_size_type<_Tp,
|
||||
typename __void_t<typename _Tp::size_type>::type> : true_type {};
|
||||
|
||||
template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
|
||||
struct __size_type
|
||||
@ -1153,16 +1124,13 @@ struct __size_type<_Alloc, _DiffType, true>
|
||||
typedef typename _Alloc::size_type type;
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_propagate_on_container_copy_assignment : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_propagate_on_container_copy_assignment
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_propagate_on_container_copy_assignment<_Tp,
|
||||
typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
|
||||
: true_type {};
|
||||
|
||||
template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
|
||||
struct __propagate_on_container_copy_assignment
|
||||
@ -1176,16 +1144,13 @@ struct __propagate_on_container_copy_assignment<_Alloc, true>
|
||||
typedef typename _Alloc::propagate_on_container_copy_assignment type;
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_propagate_on_container_move_assignment : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_propagate_on_container_move_assignment
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_propagate_on_container_move_assignment<_Tp,
|
||||
typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
|
||||
: true_type {};
|
||||
|
||||
template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
|
||||
struct __propagate_on_container_move_assignment
|
||||
@ -1199,16 +1164,13 @@ struct __propagate_on_container_move_assignment<_Alloc, true>
|
||||
typedef typename _Alloc::propagate_on_container_move_assignment type;
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_propagate_on_container_swap : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_propagate_on_container_swap
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_propagate_on_container_swap<_Tp,
|
||||
typename __void_t<typename _Tp::propagate_on_container_swap>::type>
|
||||
: true_type {};
|
||||
|
||||
template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
|
||||
struct __propagate_on_container_swap
|
||||
@ -1222,16 +1184,13 @@ struct __propagate_on_container_swap<_Alloc, true>
|
||||
typedef typename _Alloc::propagate_on_container_swap type;
|
||||
};
|
||||
|
||||
template <class _Tp, class = void>
|
||||
struct __has_is_always_equal : false_type {};
|
||||
|
||||
template <class _Tp>
|
||||
struct __has_is_always_equal
|
||||
{
|
||||
private:
|
||||
struct __two {char __lx; char __lxx;};
|
||||
template <class _Up> static __two __test(...);
|
||||
template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
|
||||
public:
|
||||
static const bool value = sizeof(__test<_Tp>(0)) == 1;
|
||||
};
|
||||
struct __has_is_always_equal<_Tp,
|
||||
typename __void_t<typename _Tp::is_always_equal>::type>
|
||||
: true_type {};
|
||||
|
||||
template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
|
||||
struct __is_always_equal
|
||||
@ -1884,7 +1843,7 @@ public:
|
||||
return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
|
||||
}
|
||||
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
|
||||
{_VSTD::__libcpp_deallocate((void*)__p);}
|
||||
{_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p));}
|
||||
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
|
||||
{return size_type(~0) / sizeof(_Tp);}
|
||||
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
||||
@ -1900,7 +1859,7 @@ public:
|
||||
void
|
||||
construct(pointer __p)
|
||||
{
|
||||
::new((void*)__p) _Tp();
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp();
|
||||
}
|
||||
# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
||||
|
||||
@ -1909,14 +1868,14 @@ public:
|
||||
void
|
||||
construct(pointer __p, _A0& __a0)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
|
||||
}
|
||||
template <class _A0>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void
|
||||
construct(pointer __p, const _A0& __a0)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
|
||||
}
|
||||
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
|
||||
template <class _A0, class _A1>
|
||||
@ -1924,28 +1883,28 @@ public:
|
||||
void
|
||||
construct(pointer __p, _A0& __a0, _A1& __a1)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0, __a1);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
||||
}
|
||||
template <class _A0, class _A1>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void
|
||||
construct(pointer __p, const _A0& __a0, _A1& __a1)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0, __a1);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
||||
}
|
||||
template <class _A0, class _A1>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void
|
||||
construct(pointer __p, _A0& __a0, const _A1& __a1)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0, __a1);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
||||
}
|
||||
template <class _A0, class _A1>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
void
|
||||
construct(pointer __p, const _A0& __a0, const _A1& __a1)
|
||||
{
|
||||
::new((void*)__p) _Tp(__a0, __a1);
|
||||
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
|
||||
}
|
||||
#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
|
||||
_LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
|
||||
@ -3890,7 +3849,9 @@ public:
|
||||
template <class _Dp>
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
_Dp* __get_deleter() const _NOEXCEPT
|
||||
{return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
|
||||
{return static_cast<_Dp*>(__cntrl_
|
||||
? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
|
||||
: nullptr);}
|
||||
#endif // _LIBCPP_NO_RTTI
|
||||
|
||||
#ifndef _LIBCPP_HAS_NO_VARIADICS
|
||||
|
@ -25,6 +25,18 @@ template <class InputIterator, class T, class BinaryOperation>
|
||||
T
|
||||
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
|
||||
|
||||
template<class InputIterator>
|
||||
typename iterator_traits<InputIterator>::value_type
|
||||
reduce(InputIterator first, InputIterator last); // C++17
|
||||
|
||||
template<class InputIterator, class T>
|
||||
T
|
||||
reduce(InputIterator first, InputIterator last, T init); // C++17
|
||||
|
||||
template<class InputIterator, class T, class BinaryOperation>
|
||||
T
|
||||
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
|
||||
|
||||
template <class InputIterator1, class InputIterator2, class T>
|
||||
T
|
||||
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
|
||||
@ -34,6 +46,23 @@ template <class InputIterator1, class InputIterator2, class T, class BinaryOpera
|
||||
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
|
||||
T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
||||
|
||||
|
||||
template<class InputIterator1, class InputIterator2, class T>
|
||||
T
|
||||
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, T init); // C++17
|
||||
|
||||
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
|
||||
T
|
||||
transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, T init,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
|
||||
|
||||
template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
|
||||
T
|
||||
transform_reduce(InputIterator first, InputIterator last, T init,
|
||||
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
|
||||
|
||||
template <class InputIterator, class OutputIterator>
|
||||
OutputIterator
|
||||
partial_sum(InputIterator first, InputIterator last, OutputIterator result);
|
||||
@ -114,6 +143,35 @@ accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOpe
|
||||
return __init;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <class _InputIterator, class _Tp, class _BinaryOp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
__init = __b(__init, *__first);
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
|
||||
{
|
||||
return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
|
||||
}
|
||||
|
||||
template <class _InputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename iterator_traits<_InputIterator>::value_type
|
||||
reduce(_InputIterator __first, _InputIterator __last)
|
||||
{
|
||||
return _VSTD::reduce(__first, __last,
|
||||
typename iterator_traits<_InputIterator>::value_type{});
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
@ -135,6 +193,41 @@ inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2
|
||||
return __init;
|
||||
}
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator __first, _InputIterator __last,
|
||||
_Tp __init, _BinaryOp __b, _UnaryOp __u)
|
||||
{
|
||||
for (; __first != __last; ++__first)
|
||||
__init = __b(__init, __u(*__first));
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2,
|
||||
class _Tp, class _BinaryOp1, class _BinaryOp2>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2)
|
||||
{
|
||||
for (; __first1 != __last1; ++__first1, (void) ++__first2)
|
||||
__init = __b1(__init, __b2(*__first1, *__first2));
|
||||
return __init;
|
||||
}
|
||||
|
||||
template <class _InputIterator1, class _InputIterator2, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_Tp
|
||||
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
|
||||
_InputIterator2 __first2, _Tp __init)
|
||||
{
|
||||
return _VSTD::transform_reduce(__first1, __last1, __first2, __init,
|
||||
_VSTD::plus<>(), _VSTD::multiplies<>());
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class _InputIterator, class _OutputIterator>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
_OutputIterator
|
||||
|
@ -16,7 +16,10 @@
|
||||
#include <clocale>
|
||||
#include <cwctype>
|
||||
#include <ctype.h>
|
||||
#if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \
|
||||
__NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
|
||||
#include <support/xlocale/__nop_locale_mgmt.h>
|
||||
#endif
|
||||
#include <support/xlocale/__posix_l_fallback.h>
|
||||
#include <support/xlocale/__strtonum_fallback.h>
|
||||
|
||||
|
@ -653,6 +653,12 @@ template <class _T1, class _T2>
|
||||
class _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
|
||||
: public integral_constant<size_t, 2> {};
|
||||
|
||||
template <size_t _Ip, class _T1, class _T2>
|
||||
class _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
|
||||
{
|
||||
static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
|
||||
};
|
||||
|
||||
template <class _T1, class _T2>
|
||||
class _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
|
||||
{
|
||||
@ -924,6 +930,12 @@ template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_t
|
||||
template <class _Tp>
|
||||
using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
|
||||
|
||||
template <class _Tp> struct __is_inplace_index_imp : false_type {};
|
||||
template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
|
||||
|
||||
template <class _Tp>
|
||||
using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 14
|
||||
|
||||
template <class _Arg, class _Result>
|
||||
|
@ -278,7 +278,7 @@ struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp>
|
||||
|
||||
template <size_t _Ip, class... _Types>
|
||||
struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
|
||||
static_assert(_Ip < sizeof...(_Types));
|
||||
static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
|
||||
using type = __type_pack_element<_Ip, _Types...>;
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}" PARENT_SCOPE)
|
||||
|
||||
# Get sources
|
||||
# FIXME: Don't use glob here
|
||||
file(GLOB LIBCXX_SOURCES ../src/*.cpp)
|
||||
if(WIN32)
|
||||
file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp)
|
||||
|
@ -842,7 +842,7 @@ void __rename(const path& from, const path& to, std::error_code *ec) {
|
||||
}
|
||||
|
||||
void __resize_file(const path& p, std::uintmax_t size, std::error_code *ec) {
|
||||
if (::truncate(p.c_str(), static_cast<long>(size)) == -1)
|
||||
if (::truncate(p.c_str(), static_cast<::off_t>(size)) == -1)
|
||||
set_or_throw(ec, "resize_file", p);
|
||||
else if (ec)
|
||||
ec->clear();
|
||||
|
@ -6158,6 +6158,4 @@ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t,
|
||||
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
|
||||
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
|
||||
|
||||
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
16
src/vector.cpp
Normal file
16
src/vector.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
//===------------------------- vector.cpp ---------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "vector"
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __vector_base_common<true>;
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
@ -23,6 +23,7 @@
|
||||
// However, for backwards compatibility, if _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
|
||||
// is defined before including <algorithm>, then random_shuffle will be restored.
|
||||
|
||||
// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
|
||||
#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -14,6 +14,7 @@
|
||||
// However, for backwards compatibility, if _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
|
||||
// is defined before including <functional>, then they will be restored.
|
||||
|
||||
// MODULES_DEFINES: _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
|
||||
#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
|
||||
|
||||
#include <functional>
|
||||
|
37
test/libcxx/include_as_c.sh.cpp
Normal file
37
test/libcxx/include_as_c.sh.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// -*- 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Test that the C wrapper headers can be included when compiling them as C.
|
||||
|
||||
// NOTE: It's not common or recommended to have libc++ in the header search
|
||||
// path when compiling C files, but it does happen often enough.
|
||||
|
||||
// RUN: %cxx -c -xc %s -fsyntax-only %flags %compile_flags -std=c99
|
||||
|
||||
#include <complex.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tgmath.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
int main() {}
|
34
test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
Normal file
34
test/libcxx/utilities/utility/__is_inplace_index.pass.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// template <class _Tp> using __is_inplace_index
|
||||
|
||||
#include <utility>
|
||||
|
||||
struct S {};
|
||||
|
||||
int main() {
|
||||
using I = std::in_place_index_t<0>;
|
||||
static_assert( std::__is_inplace_index<I>::value, "");
|
||||
static_assert( std::__is_inplace_index<const I>::value, "");
|
||||
static_assert( std::__is_inplace_index<const volatile I>::value, "");
|
||||
static_assert( std::__is_inplace_index<I&>::value, "");
|
||||
static_assert( std::__is_inplace_index<const I&>::value, "");
|
||||
static_assert( std::__is_inplace_index<const volatile I&>::value, "");
|
||||
static_assert( std::__is_inplace_index<I&&>::value, "");
|
||||
static_assert( std::__is_inplace_index<const I&&>::value, "");
|
||||
static_assert( std::__is_inplace_index<const volatile I&&>::value, "");
|
||||
static_assert(!std::__is_inplace_index<std::in_place_type_t<int>>::value, "");
|
||||
static_assert(!std::__is_inplace_index<std::in_place_t>::value, "");
|
||||
static_assert(!std::__is_inplace_index<void>::value, "");
|
||||
static_assert(!std::__is_inplace_index<int>::value, "");
|
||||
static_assert(!std::__is_inplace_index<S>::value, "");
|
||||
}
|
34
test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
Normal file
34
test/libcxx/utilities/utility/__is_inplace_type.pass.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// template <class _Tp> using __is_inplace_type
|
||||
|
||||
#include <utility>
|
||||
|
||||
struct S {};
|
||||
|
||||
int main() {
|
||||
using T = std::in_place_type_t<int>;
|
||||
static_assert( std::__is_inplace_type<T>::value, "");
|
||||
static_assert( std::__is_inplace_type<const T>::value, "");
|
||||
static_assert( std::__is_inplace_type<const volatile T>::value, "");
|
||||
static_assert( std::__is_inplace_type<T&>::value, "");
|
||||
static_assert( std::__is_inplace_type<const T&>::value, "");
|
||||
static_assert( std::__is_inplace_type<const volatile T&>::value, "");
|
||||
static_assert( std::__is_inplace_type<T&&>::value, "");
|
||||
static_assert( std::__is_inplace_type<const T&&>::value, "");
|
||||
static_assert( std::__is_inplace_type<const volatile T&&>::value, "");
|
||||
static_assert(!std::__is_inplace_type<std::in_place_index_t<0>>::value, "");
|
||||
static_assert(!std::__is_inplace_type<std::in_place_t>::value, "");
|
||||
static_assert(!std::__is_inplace_type<void>::value, "");
|
||||
static_assert(!std::__is_inplace_type<int>::value, "");
|
||||
static_assert(!std::__is_inplace_type<S>::value, "");
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// tuple_element<I, pair<T1, T2> >::type
|
||||
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::pair<int, double> P;
|
||||
std::tuple_element<2, P>::type foo; // expected-note {{requested here}}
|
||||
// expected-error@utility:* {{static_assert failed "Index out of bounds in std::tuple_element<std::pair<T1, T2>>"}}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <variant>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
|
||||
// template <size_t I, class T> struct variant_alternative; // undefined
|
||||
// template <size_t I, class T> struct variant_alternative<I, const T>;
|
||||
// template <size_t I, class T> struct variant_alternative<I, volatile T>;
|
||||
// template <size_t I, class T> struct variant_alternative<I, const volatile T>;
|
||||
// template <size_t I, class T>
|
||||
// using variant_alternative_t = typename variant_alternative<I, T>::type;
|
||||
//
|
||||
// template <size_t I, class... Types>
|
||||
// struct variant_alternative<I, variant<Types...>>;
|
||||
|
||||
|
||||
#include <variant>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::variant<int, double> T;
|
||||
std::variant_alternative<2, T>::type foo; // expected-note {{requested here}}
|
||||
// expected-error@variant:* {{static_assert failed "Index out of bounds in std::variant_alternative<>"}}
|
||||
}
|
||||
}
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::map<int, double, transparent_less> M;
|
||||
|
||||
M().count(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::map<int, double, transparent_less_not_referenceable> M;
|
||||
M().count(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::map<int, double, transparent_less> M;
|
||||
|
||||
M().equal_range(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::map<int, double, transparent_less_not_referenceable> M;
|
||||
M().equal_range(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::map<int, double, transparent_less> M;
|
||||
|
||||
M().find(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::map<int, double, transparent_less_not_referenceable> M;
|
||||
M().find(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::map<int, double, transparent_less> M;
|
||||
|
||||
M().lower_bound(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::map<int, double, transparent_less_not_referenceable> M;
|
||||
M().lower_bound(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::map<int, double, transparent_less> M;
|
||||
|
||||
M().upper_bound(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::map<int, double, transparent_less_not_referenceable> M;
|
||||
M().upper_bound(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less> M;
|
||||
|
||||
M().count(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less_not_referenceable> M;
|
||||
M().count(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less> M;
|
||||
|
||||
M().equal_range(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less_not_referenceable> M;
|
||||
M().equal_range(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less> M;
|
||||
|
||||
M().find(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less_not_referenceable> M;
|
||||
M().find(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less> M;
|
||||
|
||||
M().lower_bound(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less_not_referenceable> M;
|
||||
M().lower_bound(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,12 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less> M;
|
||||
|
||||
M().upper_bound(C2Int{5});
|
||||
}
|
||||
{
|
||||
typedef std::multimap<int, double, transparent_less_not_referenceable> M;
|
||||
M().upper_bound(C2Int{5});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <array>
|
||||
|
||||
// tuple_element<I, array<T, N> >::type
|
||||
|
||||
// Prevent -Warray-bounds from issuing a diagnostic when testing with clang verify.
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic ignored "-Warray-bounds"
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
// std::array is explicitly allowed to be initialized with A a = { init-list };.
|
||||
// Disable the missing braces warning for this reason.
|
||||
#include "disable_missing_braces_warning.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef double T;
|
||||
typedef std::array<T, 3> C;
|
||||
std::tuple_element<3, C> foo; // expected-note {{requested here}}
|
||||
// expected-error@array:* {{static_assert failed "Index out of bounds in std::tuple_element<> (std::array)"}}
|
||||
}
|
||||
}
|
@ -28,6 +28,39 @@
|
||||
|
||||
namespace coro = std::experimental;
|
||||
|
||||
struct MyCoro {
|
||||
struct promise_type {
|
||||
void unhandled_exception() {}
|
||||
void return_void() {}
|
||||
coro::suspend_never initial_suspend() { return {}; }
|
||||
coro::suspend_never final_suspend() { return {}; }
|
||||
MyCoro get_return_object() {
|
||||
do_runtime_test();
|
||||
return {};
|
||||
}
|
||||
void do_runtime_test() {
|
||||
// Test that a coroutine_handle<const T> can be created from a const
|
||||
// promise_type and that it represents the same coroutine as
|
||||
// coroutine_handle<T>
|
||||
using CH = coro::coroutine_handle<promise_type>;
|
||||
using CCH = coro::coroutine_handle<const promise_type>;
|
||||
const auto &cthis = *this;
|
||||
CH h = CH::from_promise(*this);
|
||||
CCH h2 = CCH::from_promise(*this);
|
||||
CCH h3 = CCH::from_promise(cthis);
|
||||
assert(&h.promise() == this);
|
||||
assert(&h2.promise() == this);
|
||||
assert(&h3.promise() == this);
|
||||
assert(h.address() == h2.address());
|
||||
assert(h2.address() == h3.address());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
MyCoro do_runtime_test() {
|
||||
co_await coro::suspend_never{};
|
||||
}
|
||||
|
||||
template <class Promise>
|
||||
void do_test(coro::coroutine_handle<Promise>&& H) {
|
||||
|
||||
@ -46,4 +79,6 @@ void do_test(coro::coroutine_handle<Promise>&& H) {
|
||||
int main()
|
||||
{
|
||||
do_test(coro::coroutine_handle<int>{});
|
||||
do_test(coro::coroutine_handle<const int>{});
|
||||
do_runtime_test();
|
||||
}
|
||||
|
63
test/std/numerics/numeric.ops/reduce/reduce.pass.cpp
Normal file
63
test/std/numerics/numeric.ops/reduce/reduce.pass.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template<class InputIterator>
|
||||
// typename iterator_traits<InputIterator>::value_type
|
||||
// reduce(InputIterator first, InputIterator last);
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<typename std::iterator_traits<decltype(first)>::value_type,
|
||||
decltype(std::reduce(first, last))> );
|
||||
assert(std::reduce(first, last) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
test(Iter(ia), Iter(ia), 0);
|
||||
test(Iter(ia), Iter(ia+1), 1);
|
||||
test(Iter(ia), Iter(ia+2), 3);
|
||||
test(Iter(ia), Iter(ia+sa), 21);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<T, decltype(std::reduce(p, p))> );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char>();
|
||||
test_return_type<int>();
|
||||
test_return_type<unsigned long>();
|
||||
test_return_type<float>();
|
||||
test_return_type<double>();
|
||||
|
||||
test<input_iterator<const int*> >();
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
67
test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp
Normal file
67
test/std/numerics/numeric.ops/reduce/reduce_init.pass.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template<class InputIterator, class T>
|
||||
// T reduce(InputIterator first, InputIterator last, T init);
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter, class T>
|
||||
void
|
||||
test(Iter first, Iter last, T init, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<T, decltype(std::reduce(first, last, init))> );
|
||||
assert(std::reduce(first, last, init) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
test(Iter(ia), Iter(ia), 0, 0);
|
||||
test(Iter(ia), Iter(ia), 1, 1);
|
||||
test(Iter(ia), Iter(ia+1), 0, 1);
|
||||
test(Iter(ia), Iter(ia+1), 2, 3);
|
||||
test(Iter(ia), Iter(ia+2), 0, 3);
|
||||
test(Iter(ia), Iter(ia+2), 3, 6);
|
||||
test(Iter(ia), Iter(ia+sa), 0, 21);
|
||||
test(Iter(ia), Iter(ia+sa), 4, 25);
|
||||
}
|
||||
|
||||
template <typename T, typename Init>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<Init, decltype(std::reduce(p, p, Init{}))> );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
test_return_type<int, int>();
|
||||
test_return_type<int, unsigned long>();
|
||||
test_return_type<float, int>();
|
||||
test_return_type<short, float>();
|
||||
test_return_type<double, char>();
|
||||
test_return_type<char, double>();
|
||||
|
||||
test<input_iterator<const int*> >();
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
}
|
74
test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp
Normal file
74
test/std/numerics/numeric.ops/reduce/reduce_init_op.pass.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template<class InputIterator, class T, class BinaryOperation>
|
||||
// T reduce(InputIterator first, InputIterator last, T init, BinaryOperation op);
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter, class T, class Op>
|
||||
void
|
||||
test(Iter first, Iter last, T init, Op op, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<T, decltype(std::reduce(first, last, init, op))>, "" );
|
||||
assert(std::reduce(first, last, init, op) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
test(Iter(ia), Iter(ia), 0, std::plus<>(), 0);
|
||||
test(Iter(ia), Iter(ia), 1, std::multiplies<>(), 1);
|
||||
test(Iter(ia), Iter(ia+1), 0, std::plus<>(), 1);
|
||||
test(Iter(ia), Iter(ia+1), 2, std::multiplies<>(), 2);
|
||||
test(Iter(ia), Iter(ia+2), 0, std::plus<>(), 3);
|
||||
test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), 6);
|
||||
test(Iter(ia), Iter(ia+sa), 0, std::plus<>(), 21);
|
||||
test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), 2880);
|
||||
}
|
||||
|
||||
template <typename T, typename Init>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<Init, decltype(std::reduce(p, p, Init{}, std::plus<>()))>, "" );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
test_return_type<int, int>();
|
||||
test_return_type<int, unsigned long>();
|
||||
test_return_type<float, int>();
|
||||
test_return_type<short, float>();
|
||||
test_return_type<double, char>();
|
||||
test_return_type<char, double>();
|
||||
|
||||
test<input_iterator<const int*> >();
|
||||
test<forward_iterator<const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
|
||||
// Make sure the math is done using the correct type
|
||||
{
|
||||
auto v = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
unsigned res = std::reduce(v.begin(), v.end(), 1U, std::multiplies<>());
|
||||
assert(res == 40320); // 8! will not fit into a char
|
||||
}
|
||||
}
|
@ -122,6 +122,12 @@ void basic_tests()
|
||||
assert(v[i] == 40 + triangle(i));
|
||||
}
|
||||
|
||||
{
|
||||
std::vector<int> v, res;
|
||||
std::transform_exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 40, std::plus<>(), identity<>());
|
||||
assert(res.empty());
|
||||
}
|
||||
|
||||
// Make sure that the calculations are done using the init typedef
|
||||
{
|
||||
std::vector<unsigned char> v(10);
|
@ -0,0 +1,124 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template <class InputIterator1, class T,
|
||||
// class BinaryOperation, class UnaryOperation>
|
||||
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
// T init, BinaryOperation binary_op, UnaryOperation unary_op);
|
||||
//
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class _Tp = void>
|
||||
struct identity : std::unary_function<_Tp, _Tp>
|
||||
{
|
||||
constexpr const _Tp& operator()(const _Tp& __x) const { return __x;}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct identity<void>
|
||||
{
|
||||
template <class _Tp>
|
||||
constexpr auto operator()(_Tp&& __x) const
|
||||
_NOEXCEPT_(noexcept(_VSTD::forward<_Tp>(__x)))
|
||||
-> decltype (_VSTD::forward<_Tp>(__x))
|
||||
{ return _VSTD::forward<_Tp>(__x); }
|
||||
};
|
||||
|
||||
|
||||
template <class _Tp = void>
|
||||
struct twice
|
||||
{
|
||||
constexpr const _Tp operator()(const _Tp& __x) const noexcept { return 2 * __x; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct twice<void>
|
||||
{
|
||||
template <class _Tp>
|
||||
constexpr auto operator()(const _Tp& __x) const
|
||||
_NOEXCEPT_(noexcept(2 * __x))
|
||||
-> decltype (2 * __x)
|
||||
{ return 2 * __x; }
|
||||
};
|
||||
|
||||
template <class Iter1, class T, class BOp, class UOp>
|
||||
void
|
||||
test(Iter1 first1, Iter1 last1, T init, BOp bOp, UOp uOp, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<T,
|
||||
decltype(std::transform_reduce(first1, last1, init, bOp, uOp))> );
|
||||
assert(std::transform_reduce(first1, last1, init, bOp, uOp) == x);
|
||||
}
|
||||
|
||||
template <class Iter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
|
||||
test(Iter(ia), Iter(ia), 0, std::plus<>(), identity<>(), 0);
|
||||
test(Iter(ia), Iter(ia), 1, std::multiplies<>(), identity<>(), 1);
|
||||
test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), identity<>(), 0);
|
||||
test(Iter(ia), Iter(ia+1), 2, std::plus<>(), identity<>(), 3);
|
||||
test(Iter(ia), Iter(ia+2), 0, std::plus<>(), identity<>(), 3);
|
||||
test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), identity<>(), 6);
|
||||
test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), identity<>(), 2880);
|
||||
test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), identity<>(), 25);
|
||||
|
||||
test(Iter(ia), Iter(ia), 0, std::plus<>(), twice<>(), 0);
|
||||
test(Iter(ia), Iter(ia), 1, std::multiplies<>(), twice<>(), 1);
|
||||
test(Iter(ia), Iter(ia+1), 0, std::multiplies<>(), twice<>(), 0);
|
||||
test(Iter(ia), Iter(ia+1), 2, std::plus<>(), twice<>(), 4);
|
||||
test(Iter(ia), Iter(ia+2), 0, std::plus<>(), twice<>(), 6);
|
||||
test(Iter(ia), Iter(ia+2), 3, std::multiplies<>(), twice<>(), 24);
|
||||
test(Iter(ia), Iter(ia+sa), 4, std::multiplies<>(), twice<>(), 184320); // 64 * 2880
|
||||
test(Iter(ia), Iter(ia+sa), 4, std::plus<>(), twice<>(), 46);
|
||||
}
|
||||
|
||||
template <typename T, typename Init>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<Init,
|
||||
decltype(std::transform_reduce(p, p, Init{}, std::plus<>(), identity<>()))> );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
test_return_type<int, int>();
|
||||
test_return_type<int, unsigned long>();
|
||||
test_return_type<float, int>();
|
||||
test_return_type<short, float>();
|
||||
test_return_type<double, char>();
|
||||
test_return_type<char, double>();
|
||||
|
||||
// All the iterator categories
|
||||
test<input_iterator <const int*> >();
|
||||
test<forward_iterator <const int*> >();
|
||||
test<bidirectional_iterator<const int*> >();
|
||||
test<random_access_iterator<const int*> >();
|
||||
test<const int*>();
|
||||
test< int*>();
|
||||
|
||||
// Make sure the math is done using the correct type
|
||||
{
|
||||
auto v = {1, 2, 3, 4, 5, 6};
|
||||
unsigned res = std::transform_reduce(v.begin(), v.end(), 1U, std::multiplies<>(), twice<>());
|
||||
assert(res == 46080); // 6! * 64 will not fit into a char
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template <class InputIterator1, class InputIterator2, class T>
|
||||
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
// InputIterator2 first2, T init);
|
||||
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter1, class Iter2, class T>
|
||||
void
|
||||
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<T,
|
||||
decltype(std::transform_reduce(first1, last1, first2, init))> );
|
||||
assert(std::transform_reduce(first1, last1, first2, init) == x);
|
||||
}
|
||||
|
||||
template <class SIter, class UIter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned int ua[] = {2, 4, 6, 8, 10,12};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
assert(sa == sizeof(ua) / sizeof(ua[0])); // just to be sure
|
||||
|
||||
test(SIter(ia), SIter(ia), UIter(ua), 0, 0);
|
||||
test(UIter(ua), UIter(ua), SIter(ia), 1, 1);
|
||||
test(SIter(ia), SIter(ia+1), UIter(ua), 0, 2);
|
||||
test(UIter(ua), UIter(ua+1), SIter(ia), 2, 4);
|
||||
test(SIter(ia), SIter(ia+2), UIter(ua), 0, 10);
|
||||
test(UIter(ua), UIter(ua+2), SIter(ia), 3, 13);
|
||||
test(SIter(ia), SIter(ia+sa), UIter(ua), 0, 182);
|
||||
test(UIter(ua), UIter(ua+sa), SIter(ia), 4, 186);
|
||||
}
|
||||
|
||||
template <typename T, typename Init>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<Init,
|
||||
decltype(std::transform_reduce(p, p, p, Init{}))> );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
test_return_type<int, int>();
|
||||
test_return_type<int, unsigned long>();
|
||||
test_return_type<float, int>();
|
||||
test_return_type<short, float>();
|
||||
test_return_type<double, char>();
|
||||
test_return_type<char, double>();
|
||||
|
||||
// All the iterator categories
|
||||
test<input_iterator <const int*>, input_iterator <const unsigned int*> >();
|
||||
test<input_iterator <const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<input_iterator <const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<input_iterator <const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<forward_iterator <const int*>, input_iterator <const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<bidirectional_iterator<const int*>, input_iterator <const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<random_access_iterator<const int*>, input_iterator <const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
// just plain pointers (const vs. non-const, too)
|
||||
test<const int*, const unsigned int *>();
|
||||
test<const int*, unsigned int *>();
|
||||
test< int*, const unsigned int *>();
|
||||
test< int*, unsigned int *>();
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <numeric>
|
||||
// UNSUPPORTED: c++98, c++03, c++11, c++14
|
||||
|
||||
// template <class InputIterator1, class InputIterator2, class T,
|
||||
// class BinaryOperation1, class BinaryOperation2>
|
||||
// T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
// InputIterator2 first2, T init,
|
||||
// BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
|
||||
//
|
||||
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_iterators.h"
|
||||
|
||||
template <class Iter1, class Iter2, class T, class Op1, class Op2>
|
||||
void
|
||||
test(Iter1 first1, Iter1 last1, Iter2 first2, T init, Op1 op1, Op2 op2, T x)
|
||||
{
|
||||
static_assert( std::is_same_v<T,
|
||||
decltype(std::transform_reduce(first1, last1, first2, init, op1, op2))> );
|
||||
assert(std::transform_reduce(first1, last1, first2, init, op1, op2) == x);
|
||||
}
|
||||
|
||||
template <class SIter, class UIter>
|
||||
void
|
||||
test()
|
||||
{
|
||||
int ia[] = {1, 2, 3, 4, 5, 6};
|
||||
unsigned int ua[] = {2, 4, 6, 8, 10,12};
|
||||
unsigned sa = sizeof(ia) / sizeof(ia[0]);
|
||||
assert(sa == sizeof(ua) / sizeof(ua[0])); // just to be sure
|
||||
|
||||
test(SIter(ia), SIter(ia), UIter(ua), 0, std::plus<>(), std::multiplies<>(), 0);
|
||||
test(UIter(ua), UIter(ua), SIter(ia), 1, std::multiplies<>(), std::plus<>(), 1);
|
||||
test(SIter(ia), SIter(ia+1), UIter(ua), 0, std::multiplies<>(), std::plus<>(), 0);
|
||||
test(UIter(ua), UIter(ua+1), SIter(ia), 2, std::plus<>(), std::multiplies<>(), 4);
|
||||
test(SIter(ia), SIter(ia+2), UIter(ua), 0, std::plus<>(), std::multiplies<>(), 10);
|
||||
test(UIter(ua), UIter(ua+2), SIter(ia), 3, std::multiplies<>(), std::plus<>(), 54);
|
||||
test(SIter(ia), SIter(ia+sa), UIter(ua), 4, std::multiplies<>(), std::plus<>(), 2099520);
|
||||
test(UIter(ua), UIter(ua+sa), SIter(ia), 4, std::plus<>(), std::multiplies<>(), 186);
|
||||
}
|
||||
|
||||
template <typename T, typename Init>
|
||||
void test_return_type()
|
||||
{
|
||||
T *p = nullptr;
|
||||
static_assert( std::is_same_v<Init,
|
||||
decltype(std::transform_reduce(p, p, p, Init{}, std::plus<>(), std::multiplies<>()))> );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_return_type<char, int>();
|
||||
test_return_type<int, int>();
|
||||
test_return_type<int, unsigned long>();
|
||||
test_return_type<float, int>();
|
||||
test_return_type<short, float>();
|
||||
test_return_type<double, char>();
|
||||
test_return_type<char, double>();
|
||||
|
||||
// All the iterator categories
|
||||
test<input_iterator <const int*>, input_iterator <const unsigned int*> >();
|
||||
test<input_iterator <const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<input_iterator <const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<input_iterator <const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<forward_iterator <const int*>, input_iterator <const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<forward_iterator <const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<bidirectional_iterator<const int*>, input_iterator <const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<bidirectional_iterator<const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
test<random_access_iterator<const int*>, input_iterator <const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, forward_iterator <const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, bidirectional_iterator<const unsigned int*> >();
|
||||
test<random_access_iterator<const int*>, random_access_iterator<const unsigned int*> >();
|
||||
|
||||
// just plain pointers (const vs. non-const, too)
|
||||
test<const int*, const unsigned int *>();
|
||||
test<const int*, unsigned int *>();
|
||||
test< int*, const unsigned int *>();
|
||||
test< int*, unsigned int *>();
|
||||
}
|
@ -104,7 +104,7 @@ public:
|
||||
T* allocate(std::size_t, const void* hint)
|
||||
{
|
||||
allocate_called = true;
|
||||
return (T*)hint;
|
||||
return (T*) const_cast<void *>(hint);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,17 @@ struct transparent_less
|
||||
noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
|
||||
-> decltype (std::forward<T>(t) < std::forward<U>(u))
|
||||
{ return std::forward<T>(t) < std::forward<U>(u); }
|
||||
typedef void is_transparent; // correct
|
||||
using is_transparent = void; // correct
|
||||
};
|
||||
|
||||
struct transparent_less_not_referenceable
|
||||
{
|
||||
template <class T, class U>
|
||||
constexpr auto operator()(T&& t, U&& u) const
|
||||
noexcept(noexcept(std::forward<T>(t) < std::forward<U>(u)))
|
||||
-> decltype (std::forward<T>(t) < std::forward<U>(u))
|
||||
{ return std::forward<T>(t) < std::forward<U>(u); }
|
||||
using is_transparent = void () const &; // it's a type; a weird one, but a type
|
||||
};
|
||||
|
||||
struct transparent_less_no_type
|
||||
@ -33,7 +43,7 @@ struct transparent_less_no_type
|
||||
-> decltype (std::forward<T>(t) < std::forward<U>(u))
|
||||
{ return std::forward<T>(t) < std::forward<U>(u); }
|
||||
private:
|
||||
// typedef void is_transparent; // error - should exist
|
||||
// using is_transparent = void; // error - should exist
|
||||
};
|
||||
|
||||
struct transparent_less_private
|
||||
@ -44,7 +54,7 @@ struct transparent_less_private
|
||||
-> decltype (std::forward<T>(t) < std::forward<U>(u))
|
||||
{ return std::forward<T>(t) < std::forward<U>(u); }
|
||||
private:
|
||||
typedef void is_transparent; // error - should be accessible
|
||||
using is_transparent = void; // error - should be accessible
|
||||
};
|
||||
|
||||
struct transparent_less_not_a_type
|
||||
|
@ -108,6 +108,11 @@ class Configuration(object):
|
||||
return check_value(val, env_var)
|
||||
return check_value(conf_val, name)
|
||||
|
||||
def get_modules_enabled(self):
|
||||
return self.get_lit_bool('enable_modules',
|
||||
default=False,
|
||||
env_var='LIBCXX_ENABLE_MODULES')
|
||||
|
||||
def make_static_lib_name(self, name):
|
||||
"""Return the full filename for the specified library name"""
|
||||
if self.is_windows:
|
||||
@ -631,9 +636,19 @@ class Configuration(object):
|
||||
# The __config_site header should be non-empty. Otherwise it should
|
||||
# have never been emitted by CMake.
|
||||
assert len(feature_macros) > 0
|
||||
# FIXME: This is a hack that should be fixed using module maps (or something)
|
||||
# If modules are enabled then we have to lift all of the definitions
|
||||
# in __config_site onto the command line.
|
||||
modules_enabled = self.get_modules_enabled()
|
||||
self.cxx.compile_flags += ['-Wno-macro-redefined']
|
||||
# Transform each macro name into the feature name used in the tests.
|
||||
# Ex. _LIBCPP_HAS_NO_THREADS -> libcpp-has-no-threads
|
||||
for m in feature_macros:
|
||||
if modules_enabled:
|
||||
define = '-D%s' % m
|
||||
if feature_macros[m]:
|
||||
define += '=%s' % (feature_macros[m])
|
||||
self.cxx.compile_flags += [define]
|
||||
if m == '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS':
|
||||
continue
|
||||
if m == '_LIBCPP_ABI_VERSION':
|
||||
@ -976,9 +991,7 @@ class Configuration(object):
|
||||
if platform.system() != 'Darwin':
|
||||
modules_flags += ['-Xclang', '-fmodules-local-submodule-visibility']
|
||||
supports_modules = self.cxx.hasCompileFlag(modules_flags)
|
||||
enable_modules = self.get_lit_bool('enable_modules',
|
||||
default=False,
|
||||
env_var='LIBCXX_ENABLE_MODULES')
|
||||
enable_modules = self.get_modules_enabled()
|
||||
if enable_modules and not supports_modules:
|
||||
self.lit_config.fatal(
|
||||
'-fmodules is enabled but not supported by the compiler')
|
||||
|
Loading…
x
Reference in New Issue
Block a user