From d71466871c19561c3e0738da8adb667af96213ea Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Tue, 28 Feb 2023 18:16:18 -0800 Subject: [PATCH] Modularize (#355) * Move functors like `plus` into their own file * Move `unary_negate` into its own file * Move `binary_negate` into its own file * Move `binder1st` into its own file * Move `binder2nd` into its own file * Move `pointer_to_unary_function` into its own file * Move `pointer_to_binary_function` into its own file * Move `mem_fun_ref` into its own file * Move `mem_fn` into its own file * Move `bind` to its own file * Add `perfect_forward` helper struct to * Move `not_fn` into its own file * Move `__is_transparent` helper to its own file * Implement C++20 `bind_front` also backport it to C++17 as we will need it for ranges * Add `__bind_back` helper method to functional * Add `__compose` helper method to functional * Move `default_searcher` to its own file * Move `function` to its own file * Fix compilation issues with MSVC `_D1` and `_D2` are macros defined in MSVC xmath.hpp #fixes Missing symbols in MSVC C++ compilation, many headers fail to compile #354 * Fix missing abort in unreachable.h --------- Co-authored-by: Wesley Maxey --- .../func.bind_front/bind_front.pass.cpp | 420 +++ .../func.bind_front/bind_front.verify.cpp | 52 + .../func.not_fn/not_fn.pass.cpp | 1 + .upstream-tests/test/support/callable_types.h | 187 ++ .../utils/libcudacxx/test/config.py | 2 + .../std/detail/libcxx/include/CMakeLists.txt | 18 + .../cuda/std/detail/libcxx/include/__config | 13 + .../include/__functional/binary_negate.h | 54 + .../detail/libcxx/include/__functional/bind.h | 414 +++ .../libcxx/include/__functional/bind_back.h | 73 + .../libcxx/include/__functional/bind_front.h | 64 + .../libcxx/include/__functional/binder1st.h | 57 + .../libcxx/include/__functional/binder2nd.h | 57 + .../libcxx/include/__functional/compose.h | 56 + .../include/__functional/default_searcher.h | 148 + .../libcxx/include/__functional/function.h | 1251 ++++++++ .../libcxx/include/__functional/invoke.h | 2 +- .../include/__functional/is_transparent.h | 40 + .../libcxx/include/__functional/mem_fn.h | 61 + .../libcxx/include/__functional/mem_fun_ref.h | 177 ++ .../libcxx/include/__functional/not_fn.h | 61 + .../libcxx/include/__functional/operations.h | 584 ++++ .../include/__functional/perfect_forward.h | 113 + .../__functional/pointer_to_binary_function.h | 50 + .../__functional/pointer_to_unary_function.h | 50 + .../include/__functional/unary_negate.h | 51 + .../detail/libcxx/include/__functional_base | 45 +- .../detail/libcxx/include/__utility/pair.h | 171 +- .../libcxx/include/__utility/unreachable.h | 10 +- .../cuda/std/detail/libcxx/include/algorithm | 22 +- .../cuda/std/detail/libcxx/include/cstdlib | 12 +- include/cuda/std/detail/libcxx/include/deque | 352 +-- .../cuda/std/detail/libcxx/include/functional | 2604 +---------------- include/cuda/std/detail/libcxx/include/future | 12 +- include/cuda/std/detail/libcxx/include/memory | 100 +- .../cuda/std/detail/libcxx/include/version | 2 +- libcxx/docs/FeatureTestMacroTable.rst | 4 +- 37 files changed, 4394 insertions(+), 2996 deletions(-) create mode 100644 .upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.pass.cpp create mode 100644 .upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.verify.cpp create mode 100644 .upstream-tests/test/support/callable_types.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/binary_negate.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/bind.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/bind_back.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/bind_front.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/binder1st.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/binder2nd.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/compose.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/default_searcher.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/function.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/is_transparent.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/mem_fn.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/not_fn.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/operations.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h create mode 100644 include/cuda/std/detail/libcxx/include/__functional/unary_negate.h diff --git a/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.pass.cpp b/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.pass.cpp new file mode 100644 index 0000000000..203b41de8c --- /dev/null +++ b/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.pass.cpp @@ -0,0 +1,420 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// XFAIL: nvrtc + +// functional + +// template +// constexpr unspecified bind_front(F&&, Args&&...); + +#include +#include +#include +#include +#include + +#include "callable_types.h" +#include "test_macros.h" + +struct CopyMoveInfo { + enum { none, copy, move } copy_kind; + + __host__ __device__ constexpr CopyMoveInfo() : copy_kind(none) {} + __host__ __device__ constexpr CopyMoveInfo(CopyMoveInfo const&) : copy_kind(copy) {} + __host__ __device__ constexpr CopyMoveInfo(CopyMoveInfo&&) : copy_kind(move) {} +}; + +template +struct is_bind_frontable { + template + __host__ __device__ static auto test(int) + -> decltype((void)cuda::std::bind_front(cuda::std::declval()...), cuda::std::true_type()); + + template + __host__ __device__ static cuda::std::false_type test(...); + + static constexpr bool value = decltype(test(0))::value; +}; + +struct NotCopyMove { + NotCopyMove() = delete; + NotCopyMove(const NotCopyMove&) = delete; + NotCopyMove(NotCopyMove&&) = delete; + template + __host__ __device__ void operator()(Args&& ...) const { } +}; + +struct NonConstCopyConstructible { + __host__ __device__ explicit NonConstCopyConstructible() {} + __host__ __device__ NonConstCopyConstructible(NonConstCopyConstructible&) {} +}; + +struct MoveConstructible { + __host__ __device__ explicit MoveConstructible() {} + __host__ __device__ MoveConstructible(MoveConstructible&&) {} +}; + +struct MakeTuple { + template + __host__ __device__ constexpr auto operator()(Args&& ...args) const { + return cuda::std::make_tuple(cuda::std::forward(args)...); + } +}; + +template +struct Elem { + template + __host__ __device__ constexpr bool operator==(Elem const&) const + { return X == Y; } +}; + +struct TakeAnything { + template + __host__ __device__ constexpr void operator()(Ts&&...) const {} +}; + +__host__ __device__ constexpr bool test() { + // Bind arguments, call without arguments + { + { + auto f = cuda::std::bind_front(MakeTuple{}); + assert(f() == cuda::std::make_tuple()); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}); + assert(f() == cuda::std::make_tuple(Elem<1>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}); + assert(f() == cuda::std::make_tuple(Elem<1>{}, Elem<2>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}, Elem<3>{}); + assert(f() == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<3>{})); + } + } + + // Bind no arguments, call with arguments + { + { + auto f = cuda::std::bind_front(MakeTuple{}); + assert(f(Elem<1>{}) == cuda::std::make_tuple(Elem<1>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}); + assert(f(Elem<1>{}, Elem<2>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}); + assert(f(Elem<1>{}, Elem<2>{}, Elem<3>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<3>{})); + } + } + + // Bind arguments, call with arguments + { + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}); + assert(f(Elem<10>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<10>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}); + assert(f(Elem<10>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<10>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}, Elem<3>{}); + assert(f(Elem<10>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<3>{}, Elem<10>{})); + } + + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}); + assert(f(Elem<10>{}, Elem<11>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<10>{}, Elem<11>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}); + assert(f(Elem<10>{}, Elem<11>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<10>{}, Elem<11>{})); + } + { + auto f = cuda::std::bind_front(MakeTuple{}, Elem<1>{}, Elem<2>{}, Elem<3>{}); + assert(f(Elem<10>{}, Elem<11>{}) == cuda::std::make_tuple(Elem<1>{}, Elem<2>{}, Elem<3>{}, Elem<10>{}, Elem<11>{})); + } + } + + // Basic tests with fundamental types + { + int n = 2; + int m = 1; + auto add = [](int x, int y) { return x + y; }; + auto addN = [](int a, int b, int c, int d, int e, int f) { + return a + b + c + d + e + f; + }; + + auto a = cuda::std::bind_front(add, m, n); + assert(a() == 3); + + auto b = cuda::std::bind_front(addN, m, n, m, m, m, m); + assert(b() == 7); + + auto c = cuda::std::bind_front(addN, n, m); + assert(c(1, 1, 1, 1) == 7); + + auto f = cuda::std::bind_front(add, n); + assert(f(3) == 5); + + auto g = cuda::std::bind_front(add, n, 1); + assert(g() == 3); + + auto h = cuda::std::bind_front(addN, 1, 1, 1); + assert(h(2, 2, 2) == 9); + } + + // Make sure we don't treat cuda::std::reference_wrapper specially. +#if TEST_STD_VER > 17 + { + auto add = [](cuda::std::reference_wrapper a, cuda::std::reference_wrapper b) { + return a.get() + b.get(); + }; + int i = 1, j = 2; + auto f = cuda::std::bind_front(add, cuda::std::ref(i)); + assert(f(cuda::std::ref(j)) == 3); + } +#endif + + // Make sure we can call a function that's a pointer to a member function. + { + struct MemberFunction { + __host__ __device__ constexpr bool foo(int, int) { return true; } + }; + MemberFunction value{}; + auto fn = cuda::std::bind_front(&MemberFunction::foo, value, 0); + assert(fn(0)); + } + + // Make sure that we copy the bound arguments into the unspecified-type. + { + auto add = [](int x, int y) { return x + y; }; + int n = 2; + auto i = cuda::std::bind_front(add, n, 1); + n = 100; + assert(i() == 3); + } + + // Make sure we pass the bound arguments to the function object + // with the right value category. + { + { + auto wasCopied = [](CopyMoveInfo info) { + return info.copy_kind == CopyMoveInfo::copy; + }; + CopyMoveInfo info{}; + auto copied = cuda::std::bind_front(wasCopied, info); + assert(copied()); + } + + { + auto wasMoved = [](CopyMoveInfo info) { + return info.copy_kind == CopyMoveInfo::move; + }; + CopyMoveInfo info{}; + auto moved = cuda::std::bind_front(wasMoved, info); + assert(cuda::std::move(moved)()); + } + } + + // Make sure we call the correctly cv-ref qualified operator() based on the + // value category of the bind_front unspecified-type. + { + struct F { + __host__ __device__ constexpr int operator()() & { return 1; } + __host__ __device__ constexpr int operator()() const& { return 2; } + __host__ __device__ constexpr int operator()() && { return 3; } + __host__ __device__ constexpr int operator()() const&& { return 4; } + }; + auto x = cuda::std::bind_front(F{}); + using X = decltype(x); + assert(static_cast(x)() == 1); + assert(static_cast(x)() == 2); + assert(static_cast(x)() == 3); + assert(static_cast(x)() == 4); + } + +// GCC fails with template argument deduction issues here... +#ifndef TEST_COMPILER_GCC + // Make sure the bind_front unspecified-type is NOT invocable when the call would select a + // differently-qualified operator(). + // + // For example, if the call to `operator()() &` is ill-formed, the call to the unspecified-type + // should be ill-formed and not fall back to the `operator()() const&` overload. + { + // Make sure we delete the & overload when the underlying call isn't valid + + + // There's no way to make sure we delete the const& overload when the underlying call isn't valid, + // so we can't check this one. + + // Make sure we delete the && overload when the underlying call isn't valid + { + struct F { + __host__ __device__ void operator()() & {} + __host__ __device__ void operator()() const& {} + void operator()() && = delete; + __host__ __device__ void operator()() const&& {} + }; + using X = decltype(cuda::std::bind_front(F{})); + static_assert( cuda::std::is_invocable_v); + static_assert( cuda::std::is_invocable_v); + static_assert(!cuda::std::is_invocable_v); + static_assert( cuda::std::is_invocable_v); + } + + // Make sure we delete the const&& overload when the underlying call isn't valid + { + struct F { + __host__ __device__ void operator()() & {} + __host__ __device__ void operator()() const& {} + __host__ __device__ void operator()() && {} + void operator()() const&& = delete; + }; + using X = decltype(cuda::std::bind_front(F{})); + static_assert( cuda::std::is_invocable_v); + static_assert( cuda::std::is_invocable_v); + static_assert( cuda::std::is_invocable_v); + static_assert(!cuda::std::is_invocable_v); + } + } +#endif + + // Some examples by Tim Song + { + { + struct T { }; + struct F { + __host__ __device__ void operator()(T&&) const & {} + void operator()(T&&) && = delete; + }; + using X = decltype(cuda::std::bind_front(F{})); + static_assert(!cuda::std::is_invocable_v); + } + + { + struct T { }; + struct F { + __host__ __device__ void operator()(T const&) const {} + void operator()(T&&) const = delete; + }; + using X = decltype(cuda::std::bind_front(F{}, T{})); + static_assert(!cuda::std::is_invocable_v); + } + } + + // Test properties of the constructor of the unspecified-type returned by bind_front. + { + { + MoveOnlyCallable value(true); + auto ret = cuda::std::bind_front(cuda::std::move(value), 1); + assert(ret()); + assert(ret(1, 2, 3)); + + auto ret1 = cuda::std::move(ret); + assert(!ret()); + assert(ret1()); + assert(ret1(1, 2, 3)); + + using RetT = decltype(ret); + static_assert( cuda::std::is_move_constructible::value); + static_assert(!cuda::std::is_copy_constructible::value); + static_assert(!cuda::std::is_move_assignable::value); + static_assert(!cuda::std::is_copy_assignable::value); + } + { + CopyCallable value(true); + auto ret = cuda::std::bind_front(value, 1); + assert(ret()); + assert(ret(1, 2, 3)); + + auto ret1 = cuda::std::move(ret); + assert(ret1()); + assert(ret1(1, 2, 3)); + + auto ret2 = cuda::std::bind_front(cuda::std::move(value), 1); + assert(!ret()); + assert(ret2()); + assert(ret2(1, 2, 3)); + + using RetT = decltype(ret); + static_assert( cuda::std::is_move_constructible::value); + static_assert( cuda::std::is_copy_constructible::value); + static_assert(!cuda::std::is_move_assignable::value); + static_assert(!cuda::std::is_copy_assignable::value); + } + { + CopyAssignableWrapper value(true); + using RetT = decltype(cuda::std::bind_front(value, 1)); + + static_assert(cuda::std::is_move_constructible::value); + static_assert(cuda::std::is_copy_constructible::value); + static_assert(cuda::std::is_move_assignable::value); + static_assert(cuda::std::is_copy_assignable::value); + + value(); + } + { + MoveAssignableWrapper value(true); + using RetT = decltype(cuda::std::bind_front(cuda::std::move(value), 1)); + + static_assert( cuda::std::is_move_constructible::value); + static_assert(!cuda::std::is_copy_constructible::value); + static_assert( cuda::std::is_move_assignable::value); + static_assert(!cuda::std::is_copy_assignable::value); + + value(); + } + } + + // Make sure bind_front is SFINAE friendly + { + TakeAnything takeAnything{}; + + static_assert(!cuda::std::is_constructible_v); + static_assert(!cuda::std::is_move_constructible_v); + static_assert(!is_bind_frontable::value); + static_assert(!is_bind_frontable::value); + + static_assert(!cuda::std::is_constructible_v); + static_assert( cuda::std::is_move_constructible_v); + static_assert( is_bind_frontable::value); + static_assert(!is_bind_frontable::value); + + static_assert( cuda::std::is_constructible_v); + static_assert(!cuda::std::is_move_constructible_v); + static_assert(!is_bind_frontable::value); + static_assert(!is_bind_frontable::value); + + takeAnything(); + } + + // Make sure bind_front's unspecified type's operator() is SFINAE-friendly + { + using T = decltype(cuda::std::bind_front(cuda::std::declval(), 1)); + static_assert(!cuda::std::is_invocable::value); + static_assert( cuda::std::is_invocable::value); + static_assert(!cuda::std::is_invocable::value); + static_assert(!cuda::std::is_invocable::value); + } + + return true; +} + +int main(int, char**) { + test(); + static_assert(test()); + + return 0; +} diff --git a/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.verify.cpp b/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.verify.cpp new file mode 100644 index 0000000000..4ae898f3a3 --- /dev/null +++ b/.upstream-tests/test/std/utilities/function.objects/func.bind_front/bind_front.verify.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: nvrtc + +// functional + +// template +// constexpr unspecified bind_front(F&&, Args&&...); + +#include + +#include "test_macros.h" + +__host__ __device__ constexpr int pass(const int n) { return n; } + +__host__ __device__ int simple(int n) { return n; } + +template +__host__ __device__ T do_nothing(T t) { return t; } + +struct NotMoveConst +{ + NotMoveConst(NotMoveConst &&) = delete; + NotMoveConst(NotMoveConst const&) = delete; + + __host__ __device__ NotMoveConst(int) { } +}; + +__host__ __device__ void testNotMoveConst(NotMoveConst) { } + +int main(int, char**) +{ + int n = 1; + const int c = 1; + + auto p = cuda::std::bind_front(pass, c); + static_assert(p() == 1); // expected-error-re {{{{(static_assert|static assertion)}} expression is not an integral constant expression}} + + auto d = cuda::std::bind_front(do_nothing, n); // expected-error {{no matching function for call to 'bind_front'}} + + auto t = cuda::std::bind_front(testNotMoveConst, NotMoveConst(0)); // expected-error {{no matching function for call to 'bind_front'}} + + return 0; +} diff --git a/.upstream-tests/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp b/.upstream-tests/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp index 63b0e6d09b..c5fffe719e 100644 --- a/.upstream-tests/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp +++ b/.upstream-tests/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14 +// XFAIL: nvrtc // XFAIL: pgi // TODO: there's multiple failures that appear to be all about overload resolution and SFINAE, diff --git a/.upstream-tests/test/support/callable_types.h b/.upstream-tests/test/support/callable_types.h new file mode 100644 index 0000000000..68a0cfc2a0 --- /dev/null +++ b/.upstream-tests/test/support/callable_types.h @@ -0,0 +1,187 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_CALLABLE_TYPES_H +#define TEST_CALLABLE_TYPES_H + +#include "test_macros.h" +//#include "type_id.h" + +/////////////////////////////////////////////////////////////////////////////// +// CALLABLE TEST TYPES +/////////////////////////////////////////////////////////////////////////////// + +__host__ __device__ constexpr bool returns_true() { return true; } + +template +struct MoveOnlyCallable { + MoveOnlyCallable(MoveOnlyCallable const&) = delete; + __host__ __device__ constexpr MoveOnlyCallable(MoveOnlyCallable&& other) + : value(other.value) + { other.value = !other.value; } + + template + __host__ __device__ constexpr Ret operator()(Args&&...) { return Ret{value}; } + + __host__ __device__ constexpr explicit MoveOnlyCallable(bool x) : value(x) {} + Ret value; +}; + +template +struct CopyCallable { + __host__ __device__ constexpr CopyCallable(CopyCallable const& other) + : value(other.value) {} + + __host__ __device__ constexpr CopyCallable(CopyCallable&& other) + : value(other.value) { other.value = !other.value; } + + template + __host__ __device__ constexpr Ret operator()(Args&&...) { return Ret{value}; } + + __host__ __device__ constexpr explicit CopyCallable(bool x) : value(x) {} + Ret value; +}; + + +template +struct ConstCallable { + __host__ __device__ constexpr ConstCallable(ConstCallable const& other) + : value(other.value) {} + + __host__ __device__ constexpr ConstCallable(ConstCallable&& other) + : value(other.value) { other.value = !other.value; } + + template + __host__ __device__ constexpr Ret operator()(Args&&...) const { return Ret{value}; } + + __host__ __device__ constexpr explicit ConstCallable(bool x) : value(x) {} + Ret value; +}; + + + +template +struct NoExceptCallable { + __host__ __device__ constexpr NoExceptCallable(NoExceptCallable const& other) + : value(other.value) {} + + template + __host__ __device__ constexpr Ret operator()(Args&&...) noexcept { return Ret{value}; } + + template + __host__ __device__ constexpr Ret operator()(Args&&...) const noexcept { return Ret{value}; } + + __host__ __device__ constexpr explicit NoExceptCallable(bool x) : value(x) {} + Ret value; +}; + +struct CopyAssignableWrapper { + constexpr CopyAssignableWrapper(CopyAssignableWrapper const&) = default; + constexpr CopyAssignableWrapper(CopyAssignableWrapper&&) = default; + constexpr CopyAssignableWrapper& operator=(CopyAssignableWrapper const&) = default; + constexpr CopyAssignableWrapper& operator=(CopyAssignableWrapper &&) = default; + + template + __host__ __device__ constexpr bool operator()(Args&&...) { return value; } + + __host__ __device__ constexpr explicit CopyAssignableWrapper(bool x) : value(x) {} + bool value; +}; + + +struct MoveAssignableWrapper { + constexpr MoveAssignableWrapper(MoveAssignableWrapper const&) = delete; + constexpr MoveAssignableWrapper(MoveAssignableWrapper&&) = default; + constexpr MoveAssignableWrapper& operator=(MoveAssignableWrapper const&) = delete; + constexpr MoveAssignableWrapper& operator=(MoveAssignableWrapper &&) = default; + + template + __host__ __device__ constexpr bool operator()(Args&&...) { return value; } + + __host__ __device__ constexpr explicit MoveAssignableWrapper(bool x) : value(x) {} + bool value; +}; + +struct MemFunCallable { + __host__ __device__ constexpr explicit MemFunCallable(bool x) : value(x) {} + + __host__ __device__ constexpr bool return_value() const { return value; } + __host__ __device__ constexpr bool return_value_nc() { return value; } + bool value; +}; + +enum CallType : unsigned { + CT_None, + CT_NonConst = 1, + CT_Const = 2, + CT_LValue = 4, + CT_RValue = 8 +}; + +__host__ __device__ inline constexpr CallType operator|(CallType LHS, CallType RHS) { + return static_cast(static_cast(LHS) | static_cast(RHS)); +} +#if 0 +struct ForwardingCallObject { + struct State { + CallType last_call_type = CT_None; + TypeID const& (*last_call_args)() = nullptr; + + template + __host__ __device__ constexpr void set_call(CallType type) { + assert(last_call_type == CT_None); + assert(last_call_args == nullptr); + last_call_type = type; + last_call_args = &makeArgumentID; + } + + template + __host__ __device__ constexpr bool check_call(CallType type) { + bool result = + last_call_type == type + && last_call_args + && *last_call_args == &makeArgumentID; + last_call_type = CT_None; + last_call_args = nullptr; + return result; + } + }; + + State *st_; + + __host__ __device__ explicit constexpr ForwardingCallObject(State& st) : st_(&st) {} + + template + __host__ __device__ constexpr bool operator()(Args&&...) & { + st_->set_call(CT_NonConst | CT_LValue); + return true; + } + + template + __host__ __device__ constexpr bool operator()(Args&&...) const & { + st_->set_call(CT_Const | CT_LValue); + return true; + } + + // Don't allow the call operator to be invoked as an rvalue. + template + __host__ __device__ constexpr bool operator()(Args&&...) && { + st_->set_call(CT_NonConst | CT_RValue); + return true; + } + + template + __host__ __device__ constexpr bool operator()(Args&&...) const && { + st_->set_call(CT_Const | CT_RValue); + return true; + } +}; +#endif + +#endif // TEST_CALLABLE_TYPES_H diff --git a/.upstream-tests/utils/libcudacxx/test/config.py b/.upstream-tests/utils/libcudacxx/test/config.py index 2b929e8b19..a7f27f84ff 100644 --- a/.upstream-tests/utils/libcudacxx/test/config.py +++ b/.upstream-tests/utils/libcudacxx/test/config.py @@ -1094,6 +1094,8 @@ def configure_warnings(self): self.cxx.warning_flags += [ '-Xcompiler', '-wd4180' ] # warning C4309: 'moo': truncation of constant value self.cxx.warning_flags += [ '-Xcompiler', '-wd4309' ] + # warning C4996: deprecation warnings + self.cxx.warning_flags += [ '-Xcompiler', '-wd4996' ] else: # TODO: Re-enable soon. def addIfHostSupports(flag): diff --git a/include/cuda/std/detail/libcxx/include/CMakeLists.txt b/include/cuda/std/detail/libcxx/include/CMakeLists.txt index 2170384c93..e3abcb9b81 100644 --- a/include/cuda/std/detail/libcxx/include/CMakeLists.txt +++ b/include/cuda/std/detail/libcxx/include/CMakeLists.txt @@ -29,11 +29,29 @@ set(files __concepts/totally_ordered.h __debug __functional/binary_function.h + __functional/binary_negate.h + __functional/bind_back.h + __functional/bind_front.h + __functional/bind.h + __functional/binder1st.h + __functional/binder2nd.h + __functional/compose.h + __functional/default_searcher.h + __functional/function.h __functional/hash.h __functional/identity.h __functional/invoke.h + __functional/is_transparent.h + __functional/mem_fn.h + __functional/mem_fun_ref.h + __functional/not_fn.h + __functional/operations.h + __functional/perfect_forward.h + __functional/pointer_to_binary_function.h + __functional/pointer_to_unary_function.h __functional/reference_wrapper.h __functional/unary_function.h + __functional/unary_negate.h __functional/unwrap_ref.h __functional/weak_result_type.h __functional_03 diff --git a/include/cuda/std/detail/libcxx/include/__config b/include/cuda/std/detail/libcxx/include/__config index c0c42a5c60..95c4b79ae6 100644 --- a/include/cuda/std/detail/libcxx/include/__config +++ b/include/cuda/std/detail/libcxx/include/__config @@ -2082,6 +2082,19 @@ extern "C" _LIBCUDACXX_FUNC_VIS void __sanitizer_annotate_contiguous_container( # define _LIBCUDACXX_SYS_CLOCK_DURATION microseconds #endif +// There are a handful of public standard library types that are intended to +// support CTAD but don't need any explicit deduction guides to do so. This +// macro is used to mark them as such, which suppresses the +// '-Wctad-maybe-unsupported' compiler warning when CTAD is used in user code +// with these classes. +#if _LIBCUDACXX_STD_VER >= 17 +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) \ + template \ + _ClassName(typename _Tag::__allow_ctad...) -> _ClassName<_Tag...> +#else +# define _LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(_ClassName) static_assert(true, "") +#endif + #if defined(__CUDA_ARCH__) # define _LIBCUDACXX_CPO_ACCESSIBILITY static __device__ #else diff --git a/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h b/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h new file mode 100644 index 0000000000..74b76c58d5 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/binary_negate.h @@ -0,0 +1,54 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H +#define _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 binary_negate + : public __binary_function +{ + _Predicate __pred_; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 + binary_negate(const _Predicate& __pred) : __pred_(__pred) {} + + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const typename _Predicate::first_argument_type& __x, + const typename _Predicate::second_argument_type& __y) const + {return !__pred_(__x, __y);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY +binary_negate<_Predicate> +not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} + +#endif // _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINARY_NEGATE_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/bind.h b/include/cuda/std/detail/libcxx/include/__functional/bind.h new file mode 100644 index 0000000000..e81b90d954 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/bind.h @@ -0,0 +1,414 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_H + +// `cuda::std::bind` is not currently supported. + +#ifndef __cuda_std__ + +#ifndef __cuda_std__ +#include <__config> +#include +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/reference_wrapper.h" +#include "../__functional/weak_result_type.h" +#include "../__type_traits/conditional.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_convertible.h" +#include "../__type_traits/is_same.h" +#include "../__type_traits/is_void.h" +#include "../__type_traits/remove_cvref.h" +#include "../__type_traits/remove_reference.h" +#include "../__utility/forward.h" + +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +struct is_bind_expression : _If< + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, + false_type, + is_bind_expression<__remove_cvref_t<_Tp> > +> {}; + +#if _LIBCUDACXX_STD_VER > 14 +template +inline constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; +#endif + +template +struct is_placeholder : _If< + _IsSame<_Tp, __remove_cvref_t<_Tp> >::value, + integral_constant, + is_placeholder<__remove_cvref_t<_Tp> > +> {}; + +#if _LIBCUDACXX_STD_VER > 14 +template +inline constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; +#endif + +namespace placeholders +{ + +template struct __ph {}; + +#if defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) +_LIBCUDACXX_FUNC_VIS extern const __ph<1> _1; +_LIBCUDACXX_FUNC_VIS extern const __ph<2> _2; +_LIBCUDACXX_FUNC_VIS extern const __ph<3> _3; +_LIBCUDACXX_FUNC_VIS extern const __ph<4> _4; +_LIBCUDACXX_FUNC_VIS extern const __ph<5> _5; +_LIBCUDACXX_FUNC_VIS extern const __ph<6> _6; +_LIBCUDACXX_FUNC_VIS extern const __ph<7> _7; +_LIBCUDACXX_FUNC_VIS extern const __ph<8> _8; +_LIBCUDACXX_FUNC_VIS extern const __ph<9> _9; +_LIBCUDACXX_FUNC_VIS extern const __ph<10> _10; +#else +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<1> _1{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<2> _2{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<3> _3{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<4> _4{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<5> _5{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<6> _6{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<7> _7{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<8> _8{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<9> _9{}; +/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<10> _10{}; +#endif // defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) + +} // namespace placeholders + +template +struct is_placeholder > + : public integral_constant {}; + + +#ifndef _LIBCUDACXX_CXX03_LANG + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +_Tp& +__mu(reference_wrapper<_Tp> __t, _Uj&) +{ + return __t.get(); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +typename __invoke_of<_Ti&, _Uj...>::type +__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) +{ + return __ti(_CUDA_VSTD::forward<_Uj>(_CUDA_VSTD::get<_Indx>(__uj))...); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + is_bind_expression<_Ti>::value, + __invoke_of<_Ti&, _Uj...> +> +__mu(_Ti& __ti, tuple<_Uj...>& __uj) +{ + typedef typename __make_tuple_indices::type __indices; + return _CUDA_VSTD::__mu_expand(__ti, __uj, __indices()); +} + +template +struct __mu_return2 {}; + +template +struct __mu_return2 +{ + typedef typename tuple_element::value - 1, _Uj>::type type; +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + 0 < is_placeholder<_Ti>::value, + typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type +> +__mu(_Ti&, _Uj& __uj) +{ + const size_t _Indx = is_placeholder<_Ti>::value - 1; + return _CUDA_VSTD::forward::type>(_CUDA_VSTD::get<_Indx>(__uj)); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__enable_if_t +< + !is_bind_expression<_Ti>::value && + is_placeholder<_Ti>::value == 0 && + !__is_reference_wrapper<_Ti>::value, + _Ti& +> +__mu(_Ti& __ti, _Uj&) +{ + return __ti; +} + +template +struct __mu_return_impl; + +template +struct __mu_return_invokable // false +{ + typedef __nat type; +}; + +template +struct __mu_return_invokable +{ + typedef typename __invoke_of<_Ti&, _Uj...>::type type; +}; + +template +struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > + : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> +{ +}; + +template +struct __mu_return_impl<_Ti, false, false, true, _TupleUj> +{ + typedef typename tuple_element::value - 1, + _TupleUj>::type&& type; +}; + +template +struct __mu_return_impl<_Ti, true, false, false, _TupleUj> +{ + typedef typename _Ti::type& type; +}; + +template +struct __mu_return_impl<_Ti, false, false, false, _TupleUj> +{ + typedef _Ti& type; +}; + +template +struct __mu_return + : public __mu_return_impl<_Ti, + __is_reference_wrapper<_Ti>::value, + is_bind_expression<_Ti>::value, + 0 < is_placeholder<_Ti>::value && + is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, + _TupleUj> +{ +}; + +template +struct __is_valid_bind_return +{ + static const bool value = false; +}; + +template +struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; +}; + +template +struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> +{ + static const bool value = __invokable<_Fp, + typename __mu_return::type...>::value; +}; + +template ::value> +struct __bind_return; + +template +struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> +{ + typedef typename __invoke_of + < + _Fp&, + typename __mu_return + < + const _BoundArgs, + _TupleUj + >::type... + >::type type; +}; + +template +using __bind_return_t = typename __bind_return<_Fp, _BoundArgs, _TupleUj>::type; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +__bind_return_t<_Fp, _BoundArgs, _Args> +__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, + _Args&& __args) +{ + return _CUDA_VSTD::__invoke(__f, _CUDA_VSTD::__mu(_CUDA_VSTD::get<_Indx>(__bound_args), __args)...); +} + +template +class __bind : public __weak_result_type<__decay_t<_Fp>> +{ +protected: + typedef __decay_t<_Fp> _Fd; + typedef tuple<__decay_t<_BoundArgs>...> _Td; +private: + _Fd __f_; + _Td __bound_args_; + + typedef typename __make_tuple_indices::type __indices; +public: + template ::value && + !is_same<__libcpp_remove_reference_t<_Gp>, + __bind>::value + >> + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit __bind(_Gp&& __f, _BA&& ...__bound_args) + : __f_(_CUDA_VSTD::forward<_Gp>(__f)), + __bound_args_(_CUDA_VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __bind_return_t<_Fd, _Td, tuple<_Args&&...>> + operator()(_Args&& ...__args) + { + return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __bind_return_t> + operator()(_Args&& ...__args) const + { + return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), + tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); + } +}; + +template +struct is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; + +template +class __bind_r + : public __bind<_Fp, _BoundArgs...> +{ + typedef __bind<_Fp, _BoundArgs...> base; + typedef typename base::_Fd _Fd; + typedef typename base::_Td _Td; +public: + typedef _Rp result_type; + + + template ::value && + !is_same<__libcpp_remove_reference_t<_Gp>, + __bind_r>::value + >> + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) + : base(_CUDA_VSTD::forward<_Gp>(__f), + _CUDA_VSTD::forward<_BA>(__bound_args)...) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __enable_if_t + < + is_convertible<__bind_return_t<_Fd, _Td, tuple<_Args&&...>>, + result_type>::value || is_void<_Rp>::value, + result_type + > + operator()(_Args&& ...__args) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __enable_if_t + < + is_convertible<__bind_return_t>, + result_type>::value || is_void<_Rp>::value, + result_type + > + operator()(_Args&& ...__args) const + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); + } +}; + +template +struct is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__bind<_Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind<_Fp, _BoundArgs...> type; + return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); +} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__bind_r<_Rp, _Fp, _BoundArgs...> +bind(_Fp&& __f, _BoundArgs&&... __bound_args) +{ + typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; + return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); +} + +#endif // _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/bind_back.h b/include/cuda/std/detail/libcxx/include/__functional/bind_back.h new file mode 100644 index 0000000000..4e6d7dbe72 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/bind_back.h @@ -0,0 +1,73 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__utility/forward.h" +#include "../__utility/integer_sequence.h" + +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +template > +struct __bind_back_op; + +template +struct __bind_back_op<_NBound, index_sequence<_Ip...>> { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Fn&& __f, _BoundArgs&& __bound_args, _Args&&... __args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...)) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)..., _CUDA_VSTD::get<_Ip>(_CUDA_VSTD::forward<_BoundArgs>(__bound_args))...); } +}; + +template +struct __bind_back_t : __perfect_forward<__bind_back_op>, _Fn, _BoundArgs> { + using __perfect_forward<__bind_back_op>, _Fn, _BoundArgs>::__perfect_forward; +}; + +template , _Fn>, + is_move_constructible>, + is_constructible, _Args>..., + is_move_constructible>... + >::value +>> +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto __bind_back(_Fn&& __f, _Args&&... __args) + noexcept(noexcept(__bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...)))) + -> decltype( __bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...))) + { return __bind_back_t, tuple...>>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::forward<_Args>(__args)...)); } + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_BACK_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/bind_front.h b/include/cuda/std/detail/libcxx/include/__functional/bind_front.h new file mode 100644 index 0000000000..298a136a58 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/bind_front.h @@ -0,0 +1,64 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H +#define _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __bind_front_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Args&& ...__args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...)) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...); } +}; + +template +struct __bind_front_t : __perfect_forward<__bind_front_op, _Fn, _BoundArgs...> { + using __perfect_forward<__bind_front_op, _Fn, _BoundArgs...>::__perfect_forward; +}; + +_LIBCUDACXX_TEMPLATE(class _Fn, class... _Args) + (requires is_constructible_v, _Fn> _LIBCUDACXX_AND + is_move_constructible_v>_LIBCUDACXX_AND + (is_constructible_v, _Args> && ...) _LIBCUDACXX_AND + (is_move_constructible_v> && ... )) +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto bind_front(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_constructible_v...>, _Args&&...>) { + return __bind_front_t, decay_t<_Args>...>(_CUDA_VSTD::forward<_Fn>(__f), _CUDA_VSTD::forward<_Args>(__args)...); +} + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BIND_FRONT_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/binder1st.h b/include/cuda/std/detail/libcxx/include/__functional/binder1st.h new file mode 100644 index 0000000000..7df5666c72 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/binder1st.h @@ -0,0 +1,57 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H +#define _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder1st + : public __unary_function +{ +protected: + __Operation op; + typename __Operation::first_argument_type value; +public: + _LIBCUDACXX_INLINE_VISIBILITY binder1st(const __Operation& __x, + const typename __Operation::first_argument_type __y) + : op(__x), value(__y) {} + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (typename __Operation::second_argument_type& __x) const + {return op(value, __x);} + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::second_argument_type& __x) const + {return op(value, __x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +binder1st<__Operation> +bind1st(const __Operation& __op, const _Tp& __x) + {return binder1st<__Operation>(__op, __x);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER1ST_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h b/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h new file mode 100644 index 0000000000..4294d9a022 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/binder2nd.h @@ -0,0 +1,57 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H +#define _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder2nd + : public __unary_function +{ +protected: + __Operation op; + typename __Operation::second_argument_type value; +public: + _LIBCUDACXX_INLINE_VISIBILITY + binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) + : op(__x), value(__y) {} + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + ( typename __Operation::first_argument_type& __x) const + {return op(__x, value);} + _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() + (const typename __Operation::first_argument_type& __x) const + {return op(__x, value);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +binder2nd<__Operation> +bind2nd(const __Operation& __op, const _Tp& __x) + {return binder2nd<__Operation>(__op, __x);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_BINDER2ND_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/compose.h b/include/cuda/std/detail/libcxx/include/__functional/compose.h new file mode 100644 index 0000000000..bcb0eb30e0 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/compose.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_COMPOSE_H +#define _LIBCUDACXX___FUNCTIONAL_COMPOSE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __compose_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + constexpr auto operator()(_Fn1&& __f1, _Fn2&& __f2, _Args&&... __args) const + noexcept(noexcept(_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...)))) + -> decltype( _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...))) + { return _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Fn2>(__f2), _CUDA_VSTD::forward<_Args>(__args)...)); } +}; + +template +struct __compose_t : __perfect_forward<__compose_op, _Fn1, _Fn2> { + using __perfect_forward<__compose_op, _Fn1, _Fn2>::__perfect_forward; +}; + +template +_LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY +constexpr auto __compose(_Fn1&& __f1, _Fn2&& __f2) + noexcept(noexcept(__compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2)))) + -> decltype( __compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2))) + { return __compose_t, decay_t<_Fn2>>(_CUDA_VSTD::forward<_Fn1>(__f1), _CUDA_VSTD::forward<_Fn2>(__f2)); } + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_COMPOSE_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h b/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h new file mode 100644 index 0000000000..b5dff81187 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/default_searcher.h @@ -0,0 +1,148 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H +#define _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +// #include "../__algorithm/search.h" +#include "../__functional/identity.h" +#include "../__functional/operations.h" +#include "../__iterator/iterator_traits.h" +#include "../__utility/pair.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +_LIBCUDACXX_EXECUTION_SPACE_SPECIFIER _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +pair<_ForwardIterator1, _ForwardIterator1> +__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + if (__first2 == __last2) + return _CUDA_VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence + while (true) + { + // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks + while (true) + { + if (__first1 == __last1) // return __last1 if no element matches *__first2 + return _CUDA_VSTD::make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + // *__first1 matches *__first2, now match elements after here + _ForwardIterator1 __m1 = __first1; + _ForwardIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) + return _CUDA_VSTD::make_pair(__first1, __m1); + if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found + return _CUDA_VSTD::make_pair(__last1, __last1); + if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 + { + ++__first1; + break; + } // else there is a match, check next elements + } + } +} + +template +_LIBCUDACXX_EXECUTION_SPACE_SPECIFIER _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 +pair<_RandomAccessIterator1, _RandomAccessIterator1> +__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _Diff1; + typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _Diff2; + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + const _Diff2 __len2 = __last2 - __first2; + if (__len2 == 0) + return _CUDA_VSTD::make_pair(__first1, __first1); + const _Diff1 __len1 = __last1 - __first1; + if (__len1 < __len2) + return _CUDA_VSTD::make_pair(__last1, __last1); + const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + + while (true) + { + while (true) + { + if (__first1 == __s) + return _CUDA_VSTD::make_pair(__last1, __last1); + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } + + _RandomAccessIterator1 __m1 = __first1; + _RandomAccessIterator2 __m2 = __first2; + while (true) + { + if (++__m2 == __last2) + return _CUDA_VSTD::make_pair(__first1, __first1 + __len2); + ++__m1; // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*__m1, *__m2)) + { + ++__first1; + break; + } + } + } +} + +#ifndef __cuda_std__ + +#if _LIBCUDACXX_STD_VER > 14 + +// default searcher +template> +class _LIBCUDACXX_TEMPLATE_VIS default_searcher { +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + default_searcher(_ForwardIterator __f, _ForwardIterator __l, + _BinaryPredicate __p = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__p) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + pair<_ForwardIterator2, _ForwardIterator2> + operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const + { + return _CUDA_VSTD::__search(__f, __l, __first_, __last_, __pred_, + typename _CUDA_VSTD::iterator_traits<_ForwardIterator>::iterator_category(), + typename _CUDA_VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); + } + +private: + _ForwardIterator __first_; + _ForwardIterator __last_; + _BinaryPredicate __pred_; +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(default_searcher); + +#endif // _LIBCUDACXX_STD_VER > 14 +#endif // __cuda_std__ + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_DEFAULT_SEARCHER_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/function.h b/include/cuda/std/detail/libcxx/include/__functional/function.h new file mode 100644 index 0000000000..32ff13aaa3 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/function.h @@ -0,0 +1,1251 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_FUNCTION_H + +#ifndef __cuda_std__ + +#ifndef __cuda_std__ +#include <__config> +#include <__functional_base> +#include +#include +#include +#include +#include +#include +#include +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/invoke.h" +#include "../__functional/unary_function.h" +#include "../__iterator/iterator_traits.h" +#include "../__utility/forward.h" +#include "../__utility/move.h" +#include "../__utility/piecewise_construct.h" +#include "../__utility/swap.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifndef _LIBCUDACXX_CXX03_LANG + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// bad_function_call + +class _LIBCUDACXX_EXCEPTION_ABI bad_function_call + : public exception +{ +#ifdef _LIBCUDACXX_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION +public: + virtual ~bad_function_call() _NOEXCEPT; + + virtual const char* what() const _NOEXCEPT; +#endif +}; + +_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY +void __throw_bad_function_call() +{ +#ifndef _LIBCUDACXX_NO_EXCEPTIONS + throw bad_function_call(); +#else + _CUDA_VSTD::abort(); +#endif +} + +template class _LIBCUDACXX_TEMPLATE_VIS function; // undefined + +namespace __function +{ + +template +struct __maybe_derive_from_unary_function +{ +}; + +template +struct __maybe_derive_from_unary_function<_Rp(_A1)> + : public __unary_function<_A1, _Rp> +{ +}; + +template +struct __maybe_derive_from_binary_function +{ +}; + +template +struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> + : public __binary_function<_A1, _A2, _Rp> +{ +}; + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Fp const&) { return true; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Fp* __ptr) { return __ptr; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Ret _Class::*__ptr) { return __ptr; } + +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(function<_Fp> const& __f) { return !!__f; } + +#ifdef _LIBCUDACXX_HAS_EXTENSION_BLOCKS +template +_LIBCUDACXX_INLINE_VISIBILITY +bool __not_null(_Rp (^__p)(_Args...)) { return __p; } +#endif + +} // namespace __function + +#ifndef _LIBCUDACXX_CXX03_LANG + +namespace __function { + +// __alloc_func holds a functor and an allocator. + +template class __alloc_func; +template +class __default_alloc_func; + +template +class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> +{ + __compressed_pair<_Fp, _Ap> __f_; + + public: + typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; + typedef _LIBCUDACXX_NODEBUG_TYPE _Ap _Alloc; + + _LIBCUDACXX_INLINE_VISIBILITY + const _Target& __target() const { return __f_.first(); } + + // WIN32 APIs may define __allocator, so use __get_allocator instead. + _LIBCUDACXX_INLINE_VISIBILITY + const _Alloc& __get_allocator() const { return __f_.second(); } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), + _CUDA_VSTD::forward_as_tuple()) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, const _Alloc& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), + _CUDA_VSTD::forward_as_tuple(__a)) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(const _Target& __f, _Alloc&& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), + _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __alloc_func(_Target&& __f, _Alloc&& __a) + : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), + _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) + { + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) + { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_.first(), + _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __alloc_func* __clone() const + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type _AA; + _AA __a(__f_.second()); + typedef __allocator_destructor<_AA> _Dp; + unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); + return __hold.release(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } + + static void __destroy_and_delete(__alloc_func* __f) { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type _FunAlloc; + _FunAlloc __a(__f->__get_allocator()); + __f->destroy(); + __a.deallocate(__f, 1); + } +}; + +template +class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { + _Fp __f_; + +public: + typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; + + _LIBCUDACXX_INLINE_VISIBILITY + const _Target& __target() const { return __f_; } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __default_alloc_func(_Target&& __f) : __f_(_CUDA_VSTD::move(__f)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __arg) { + typedef __invoke_void_return_wrapper<_Rp> _Invoker; + return _Invoker::__call(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __default_alloc_func* __clone() const { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); + __default_alloc_func* __res = + ::new ((void*)__hold.get()) __default_alloc_func(__f_); + (void)__hold.release(); + return __res; + } + + _LIBCUDACXX_INLINE_VISIBILITY + void destroy() _NOEXCEPT { __f_.~_Target(); } + + static void __destroy_and_delete(__default_alloc_func* __f) { + __f->destroy(); + __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); + } +}; + +// __base provides an abstract interface for copyable functors. + +template class _LIBCUDACXX_TEMPLATE_VIS __base; + +template +class __base<_Rp(_ArgTypes...)> +{ + __base(const __base&); + __base& operator=(const __base&); +public: + _LIBCUDACXX_INLINE_VISIBILITY __base() {} + _LIBCUDACXX_INLINE_VISIBILITY virtual ~__base() {} + virtual __base* __clone() const = 0; + virtual void __clone(__base*) const = 0; + virtual void destroy() _NOEXCEPT = 0; + virtual void destroy_deallocate() _NOEXCEPT = 0; + virtual _Rp operator()(_ArgTypes&& ...) = 0; +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT = 0; + virtual const type_info& target_type() const _NOEXCEPT = 0; +#endif // _LIBCUDACXX_NO_RTTI +}; + +// __func implements __base for a given functor type. + +template class __func; + +template +class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> + : public __base<_Rp(_ArgTypes...)> +{ + __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(_Fp&& __f) + : __f_(_CUDA_VSTD::move(__f)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(const _Fp& __f, const _Alloc& __a) + : __f_(__f, __a) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(const _Fp& __f, _Alloc&& __a) + : __f_(__f, _CUDA_VSTD::move(__a)) {} + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(_Fp&& __f, _Alloc&& __a) + : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} + + virtual __base<_Rp(_ArgTypes...)>* __clone() const; + virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; + virtual void destroy() _NOEXCEPT; + virtual void destroy_deallocate() _NOEXCEPT; + virtual _Rp operator()(_ArgTypes&&... __arg); +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(const type_info&) const _NOEXCEPT; + virtual const type_info& target_type() const _NOEXCEPT; +#endif // _LIBCUDACXX_NO_RTTI +}; + +template +__base<_Rp(_ArgTypes...)>* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + typedef __allocator_destructor<_Ap> _Dp; + unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); + return __hold.release(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const +{ + ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT +{ + __f_.destroy(); +} + +template +void +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT +{ + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + _Ap __a(__f_.__get_allocator()); + __f_.destroy(); + __a.deallocate(this, 1); +} + +template +_Rp +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) +{ + return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const void* +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT +{ + if (__ti == typeid(_Fp)) + return _CUDA_VSTD::addressof(__f_.__target()); + return nullptr; +} + +template +const type_info& +__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return typeid(_Fp); +} + +#endif // _LIBCUDACXX_NO_RTTI + +// __value_func creates a value-type from a __func. + +template class __value_func; + +template class __value_func<_Rp(_ArgTypes...)> +{ + typename aligned_storage<3 * sizeof(void*)>::type __buf_; + + typedef __base<_Rp(_ArgTypes...)> __func; + __func* __f_; + + _LIBCUDACXX_NO_CFI static __func* __as_base(void* __p) + { + return reinterpret_cast<__func*>(__p); + } + + public: + _LIBCUDACXX_INLINE_VISIBILITY + __value_func() _NOEXCEPT : __f_(nullptr) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) + : __f_(nullptr) + { + typedef allocator_traits<_Alloc> __alloc_traits; + typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type _FunAlloc; + + if (__function::__not_null(__f)) + { + _FunAlloc __af(__a); + if (sizeof(_Fun) <= sizeof(__buf_) && + is_nothrow_copy_constructible<_Fp>::value && + is_nothrow_copy_constructible<_FunAlloc>::value) + { + __f_ = + ::new ((void*)&__buf_) _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) _Fun(_CUDA_VSTD::move(__f), _Alloc(__a)); + __f_ = __hold.release(); + } + } + } + + template , __value_func>::value>> + _LIBCUDACXX_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) + : __value_func(_CUDA_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {} + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func(const __value_func& __f) + { + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + __f_ = __f.__f_->__clone(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func(__value_func&& __f) _NOEXCEPT + { + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__value_func() + { + if ((void*)__f_ == &__buf_) + __f_->destroy(); + else if (__f_) + __f_->destroy_deallocate(); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func& operator=(__value_func&& __f) + { + *this = nullptr; + if (__f.__f_ == nullptr) + __f_ = nullptr; + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f_ = __as_base(&__buf_); + __f.__f_->__clone(__f_); + } + else + { + __f_ = __f.__f_; + __f.__f_ = nullptr; + } + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __value_func& operator=(nullptr_t) + { + __func* __f = __f_; + __f_ = nullptr; + if ((void*)__f == &__buf_) + __f->destroy(); + else if (__f) + __f->destroy_deallocate(); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + if (__f_ == nullptr) + __throw_bad_function_call(); + return (*__f_)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void swap(__value_func& __f) _NOEXCEPT + { + if (&__f == this) + return; + if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) + { + typename aligned_storage::type __tempbuf; + __func* __t = __as_base(&__tempbuf); + __f_->__clone(__t); + __f_->destroy(); + __f_ = nullptr; + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = nullptr; + __f_ = __as_base(&__buf_); + __t->__clone(__as_base(&__f.__buf_)); + __t->destroy(); + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f_ == &__buf_) + { + __f_->__clone(__as_base(&__f.__buf_)); + __f_->destroy(); + __f_ = __f.__f_; + __f.__f_ = __as_base(&__f.__buf_); + } + else if ((void*)__f.__f_ == &__f.__buf_) + { + __f.__f_->__clone(__as_base(&__buf_)); + __f.__f_->destroy(); + __f.__f_ = __f_; + __f_ = __as_base(&__buf_); + } + else + _CUDA_VSTD::swap(__f_, __f.__f_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; } + +#ifndef _LIBCUDACXX_NO_RTTI + _LIBCUDACXX_INLINE_VISIBILITY + const type_info& target_type() const _NOEXCEPT + { + if (__f_ == nullptr) + return typeid(void); + return __f_->target_type(); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__f_ == nullptr) + return nullptr; + return (const _Tp*)__f_->target(typeid(_Tp)); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +// Storage for a functor object, to be used with __policy to manage copy and +// destruction. +union __policy_storage +{ + mutable char __small[sizeof(void*) * 2]; + void* __large; +}; + +// True if _Fun can safely be held in __policy_storage.__small. +template +struct __use_small_storage + : public integral_constant< + bool, sizeof(_Fun) <= sizeof(__policy_storage) && + _LIBCUDACXX_ALIGNOF(_Fun) <= _LIBCUDACXX_ALIGNOF(__policy_storage) && + is_trivially_copy_constructible<_Fun>::value && + is_trivially_destructible<_Fun>::value> {}; + +// Policy contains information about how to copy, destroy, and move the +// underlying functor. You can think of it as a vtable of sorts. +struct __policy +{ + // Used to copy or destroy __large values. null for trivial objects. + void* (*const __clone)(const void*); + void (*const __destroy)(void*); + + // True if this is the null policy (no value). + const bool __is_null; + + // The target type. May be null if RTTI is disabled. + const type_info* const __type_info; + + // Returns a pointer to a static policy object suitable for the functor + // type. + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* __create() + { + return __choose_policy<_Fun>(__use_small_storage<_Fun>()); + } + + _LIBCUDACXX_INLINE_VISIBILITY + static const __policy* __create_empty() + { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = {nullptr, nullptr, + true, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(void) +#else + nullptr +#endif + }; + return &__policy_; + } + + private: + template static void* __large_clone(const void* __s) + { + const _Fun* __f = static_cast(__s); + return __f->__clone(); + } + + template + static void __large_destroy(void* __s) { + _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ false_type) { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { + &__large_clone<_Fun>, &__large_destroy<_Fun>, false, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY static const __policy* + __choose_policy(/* is_small = */ true_type) + { + static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { + nullptr, nullptr, false, +#ifndef _LIBCUDACXX_NO_RTTI + &typeid(typename _Fun::_Target) +#else + nullptr +#endif + }; + return &__policy_; + } +}; + +// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is +// faster for types that can be passed in registers. +template +using __fast_forward = __conditional_t::value, _Tp, _Tp&&>; + +// __policy_invoker calls an instance of __alloc_func held in __policy_storage. + +template struct __policy_invoker; + +template +struct __policy_invoker<_Rp(_ArgTypes...)> +{ + typedef _Rp (*__Call)(const __policy_storage*, + __fast_forward<_ArgTypes>...); + + __Call __call_; + + // Creates an invoker that throws bad_function_call. + _LIBCUDACXX_INLINE_VISIBILITY + __policy_invoker() : __call_(&__call_empty) {} + + // Creates an invoker that calls the given instance of __func. + template + _LIBCUDACXX_INLINE_VISIBILITY static __policy_invoker __create() + { + return __policy_invoker(&__call_impl<_Fun>); + } + + private: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __policy_invoker(__Call __c) : __call_(__c) {} + + static _Rp __call_empty(const __policy_storage*, + __fast_forward<_ArgTypes>...) + { + __throw_bad_function_call(); + } + + template + static _Rp __call_impl(const __policy_storage* __buf, + __fast_forward<_ArgTypes>... __args) + { + _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value + ? &__buf->__small + : __buf->__large); + return (*__f)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +// __policy_func uses a __policy and __policy_invoker to create a type-erased, +// copyable functor. + +template class __policy_func; + +template class __policy_func<_Rp(_ArgTypes...)> +{ + // Inline storage for small objects. + __policy_storage __buf_; + + // Calls the value stored in __buf_. This could technically be part of + // policy, but storing it here eliminates a level of indirection inside + // operator(). + typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; + __invoker __invoker_; + + // The policy that describes how to move / copy / destroy __buf_. Never + // null, even if the function is empty. + const __policy* __policy_; + + public: + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func() : __policy_(__policy::__create_empty()) {} + + template + _LIBCUDACXX_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) + : __policy_(__policy::__create_empty()) + { + typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type _FunAlloc; + + if (__function::__not_null(__f)) + { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + + _FunAlloc __af(__a); + if (__use_small_storage<_Fun>()) + { + ::new ((void*)&__buf_.__small) + _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + } + else + { + typedef __allocator_destructor<_FunAlloc> _Dp; + unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); + ::new ((void*)__hold.get()) + _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); + __buf_.__large = __hold.release(); + } + } + } + + template , __policy_func>::value>> + _LIBCUDACXX_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) + : __policy_(__policy::__create_empty()) { + typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; + + if (__function::__not_null(__f)) { + __invoker_ = __invoker::template __create<_Fun>(); + __policy_ = __policy::__create<_Fun>(); + if (__use_small_storage<_Fun>()) { + ::new ((void*)&__buf_.__small) _Fun(_CUDA_VSTD::move(__f)); + } else { + __builtin_new_allocator::__holder_t __hold = + __builtin_new_allocator::__allocate_type<_Fun>(1); + __buf_.__large = ::new ((void*)__hold.get()) _Fun(_CUDA_VSTD::move(__f)); + (void)__hold.release(); + } + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func(const __policy_func& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__clone) + __buf_.__large = __policy_->__clone(__f.__buf_.__large); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func(__policy_func&& __f) + : __buf_(__f.__buf_), __invoker_(__f.__invoker_), + __policy_(__f.__policy_) + { + if (__policy_->__destroy) + { + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + } + } + + _LIBCUDACXX_INLINE_VISIBILITY + ~__policy_func() + { + if (__policy_->__destroy) + __policy_->__destroy(__buf_.__large); + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func& operator=(__policy_func&& __f) + { + *this = nullptr; + __buf_ = __f.__buf_; + __invoker_ = __f.__invoker_; + __policy_ = __f.__policy_; + __f.__policy_ = __policy::__create_empty(); + __f.__invoker_ = __invoker(); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + __policy_func& operator=(nullptr_t) + { + const __policy* __p = __policy_; + __policy_ = __policy::__create_empty(); + __invoker_ = __invoker(); + if (__p->__destroy) + __p->__destroy(__buf_.__large); + return *this; + } + + _LIBCUDACXX_INLINE_VISIBILITY + _Rp operator()(_ArgTypes&&... __args) const + { + return __invoker_.__call_(_CUDA_VSTD::addressof(__buf_), + _CUDA_VSTD::forward<_ArgTypes>(__args)...); + } + + _LIBCUDACXX_INLINE_VISIBILITY + void swap(__policy_func& __f) + { + _CUDA_VSTD::swap(__invoker_, __f.__invoker_); + _CUDA_VSTD::swap(__policy_, __f.__policy_); + _CUDA_VSTD::swap(__buf_, __f.__buf_); + } + + _LIBCUDACXX_INLINE_VISIBILITY + explicit operator bool() const _NOEXCEPT + { + return !__policy_->__is_null; + } + +#ifndef _LIBCUDACXX_NO_RTTI + _LIBCUDACXX_INLINE_VISIBILITY + const type_info& target_type() const _NOEXCEPT + { + return *__policy_->__type_info; + } + + template + _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT + { + if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) + return nullptr; + if (__policy_->__clone) // Out of line storage. + return reinterpret_cast(__buf_.__large); + else + return reinterpret_cast(&__buf_.__small); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +#if defined(_LIBCUDACXX_HAS_BLOCKS_RUNTIME) + +extern "C" void *_Block_copy(const void *); +extern "C" void _Block_release(const void *); + +template +class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> + : public __base<_Rp(_ArgTypes...)> +{ + typedef _Rp1(^__block_type)(_ArgTypes1...); + __block_type __f_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(__block_type const& __f) +#ifdef _LIBCUDACXX_HAS_OBJC_ARC + : __f_(__f) +#else + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) +#endif + { } + + // [TODO] add && to save on a retain + + _LIBCUDACXX_INLINE_VISIBILITY + explicit __func(__block_type __f, const _Alloc& /* unused */) +#ifdef _LIBCUDACXX_HAS_OBJC_ARC + : __f_(__f) +#else + : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) +#endif + { } + + virtual __base<_Rp(_ArgTypes...)>* __clone() const { + _LIBCUDACXX_ASSERT(false, + "Block pointers are just pointers, so they should always fit into " + "std::function's small buffer optimization. This function should " + "never be invoked."); + return nullptr; + } + + virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { + ::new ((void*)__p) __func(__f_); + } + + virtual void destroy() _NOEXCEPT { +#ifndef _LIBCUDACXX_HAS_OBJC_ARC + if (__f_) + _Block_release(__f_); +#endif + __f_ = 0; + } + + virtual void destroy_deallocate() _NOEXCEPT { + _LIBCUDACXX_ASSERT(false, + "Block pointers are just pointers, so they should always fit into " + "std::function's small buffer optimization. This function should " + "never be invoked."); + } + + virtual _Rp operator()(_ArgTypes&& ... __arg) { + return _CUDA_VSTD::__invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...); + } + +#ifndef _LIBCUDACXX_NO_RTTI + virtual const void* target(type_info const& __ti) const _NOEXCEPT { + if (__ti == typeid(__func::__block_type)) + return &__f_; + return (const void*)nullptr; + } + + virtual const type_info& target_type() const _NOEXCEPT { + return typeid(__func::__block_type); + } +#endif // _LIBCUDACXX_NO_RTTI +}; + +#endif // _LIBCUDACXX_HAS_EXTENSION_BLOCKS + +} // namespace __function + +template +class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_ArgTypes...)> + : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, + public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> +{ +#ifndef _LIBCUDACXX_ABI_OPTIMIZED_FUNCTION + typedef __function::__value_func<_Rp(_ArgTypes...)> __func; +#else + typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; +#endif + + __func __f_; + + template , function>, + __invokable<_Fp, _ArgTypes...> + >::value> + struct __callable; + template + struct __callable<_Fp, true> + { + static const bool value = is_void<_Rp>::value || + __is_core_convertible::type, + _Rp>::value; + }; + template + struct __callable<_Fp, false> + { + static const bool value = false; + }; + + template + using _EnableIfLValueCallable = __enable_if_t<__callable<_Fp&>::value>; +public: + typedef _Rp result_type; + + // construct/copy/destroy: + _LIBCUDACXX_INLINE_VISIBILITY + function() _NOEXCEPT { } + _LIBCUDACXX_INLINE_VISIBILITY + function(nullptr_t) _NOEXCEPT {} + function(const function&); + function(function&&) _NOEXCEPT; + template> + function(_Fp); + +#if _LIBCUDACXX_STD_VER <= 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} + template + _LIBCUDACXX_INLINE_VISIBILITY + function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} + template + function(allocator_arg_t, const _Alloc&, const function&); + template + function(allocator_arg_t, const _Alloc&, function&&); + template> + function(allocator_arg_t, const _Alloc& __a, _Fp __f); +#endif + + function& operator=(const function&); + function& operator=(function&&) _NOEXCEPT; + function& operator=(nullptr_t) _NOEXCEPT; + template>> + function& operator=(_Fp&&); + + ~function(); + + // function modifiers: + void swap(function&) _NOEXCEPT; + +#if _LIBCUDACXX_STD_VER <= 14 + template + _LIBCUDACXX_INLINE_VISIBILITY + void assign(_Fp&& __f, const _Alloc& __a) + {function(allocator_arg, __a, _CUDA_VSTD::forward<_Fp>(__f)).swap(*this);} +#endif + + // function capacity: + _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { + return static_cast(__f_); + } + + // deleted overloads close possible hole in the type system + template + bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; + template + bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; +public: + // function invocation: + _Rp operator()(_ArgTypes...) const; + +#ifndef _LIBCUDACXX_NO_RTTI + // function target access: + const type_info& target_type() const _NOEXCEPT; + template _Tp* target() _NOEXCEPT; + template const _Tp* target() const _NOEXCEPT; +#endif // _LIBCUDACXX_NO_RTTI +}; + +#if _LIBCUDACXX_STD_VER > 14 +template +function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; + +template +struct __strip_signature; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; + +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; +template +struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; + +template::type> +function(_Fp) -> function<_Stripped>; +#endif // _LIBCUDACXX_STD_VER > 14 + +template +function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + const function& __f) : __f_(__f.__f_) {} +#endif + +template +function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT + : __f_(_CUDA_VSTD::move(__f.__f_)) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, + function&& __f) + : __f_(_CUDA_VSTD::move(__f.__f_)) {} +#endif + +template +template +function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} + +#if _LIBCUDACXX_STD_VER <= 14 +template +template +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, + _Fp __f) + : __f_(_CUDA_VSTD::move(__f), __a) {} +#endif + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(const function& __f) +{ + function(__f).swap(*this); + return *this; +} + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT +{ + __f_ = _CUDA_VSTD::move(__f.__f_); + return *this; +} + +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT +{ + __f_ = nullptr; + return *this; +} + +template +template +function<_Rp(_ArgTypes...)>& +function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) +{ + function(_CUDA_VSTD::forward<_Fp>(__f)).swap(*this); + return *this; +} + +template +function<_Rp(_ArgTypes...)>::~function() {} + +template +void +function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT +{ + __f_.swap(__f.__f_); +} + +template +_Rp +function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const +{ + return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); +} + +#ifndef _LIBCUDACXX_NO_RTTI + +template +const type_info& +function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT +{ + return __f_.target_type(); +} + +template +template +_Tp* +function<_Rp(_ArgTypes...)>::target() _NOEXCEPT +{ + return (_Tp*)(__f_.template target<_Tp>()); +} + +template +template +const _Tp* +function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT +{ + return __f_.template target<_Tp>(); +} + +#endif // _LIBCUDACXX_NO_RTTI + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +bool +operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} + +template +inline _LIBCUDACXX_INLINE_VISIBILITY +void +swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT +{return __x.swap(__y);} + +#else // _LIBCUDACXX_CXX03_LANG + +#include <__functional_03> + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX_CXX03_LANG + +#endif // __cuda_std__ + +#endif // _LIBCUDACXX___FUNCTIONAL_FUNCTION_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/invoke.h b/include/cuda/std/detail/libcxx/include/__functional/invoke.h index 881722f2aa..5355322272 100644 --- a/include/cuda/std/detail/libcxx/include/__functional/invoke.h +++ b/include/cuda/std/detail/libcxx/include/__functional/invoke.h @@ -548,7 +548,7 @@ using invoke_result_t = typename invoke_result<_Fn, _Args...>::type; #if _LIBCUDACXX_STD_VER > 14 template -_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 invoke_result_t<_Fn, _Args...> +_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 invoke_result_t<_Fn, _Args...> invoke(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_v<_Fn, _Args...>) { diff --git a/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h b/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h new file mode 100644 index 0000000000..ef50bd48e8 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/is_transparent.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT +#define _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__type_traits/integral_constant.h" +#include "../__type_traits/void_t.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 11 + +template +struct __is_transparent : false_type {}; + +template +struct __is_transparent<_Tp, _Up, __void_t > + : true_type {}; + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_IS_TRANSPARENT diff --git a/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h b/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h new file mode 100644 index 0000000000..f186605888 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/mem_fn.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_MEM_FN_H +#define _LIBCUDACXX___FUNCTIONAL_MEM_FN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/invoke.h" +#include "../__functional/weak_result_type.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +template +class __mem_fn : public __weak_result_type<_Tp> +{ +public: + // types + typedef _Tp type; +private: + type __f_; + +public: + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} + + // invoke + template + _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 + typename __invoke_return::type + operator() (_ArgTypes&&... __args) const { + return _CUDA_VSTD::__invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__args)...); + } +}; + +template +inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 +__mem_fn<_Rp _Tp::*> +mem_fn(_Rp _Tp::* __pm) _NOEXCEPT +{ + return __mem_fn<_Rp _Tp::*>(__pm); +} + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_MEM_FN_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h b/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h new file mode 100644 index 0000000000..33d6f6e63a --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/mem_fun_ref.h @@ -0,0 +1,177 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H +#define _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_t + : public __unary_function<_Tp*, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_t + : public __binary_function<_Tp*, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)()) + {return mem_fun_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_ref_t + : public __unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)(); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_ref_t + : public __binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)()) + {return mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) + {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_t + : public __unary_function +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const + {return (__p->*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_t + : public __binary_function +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const + {return (__p->*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun_t<_Sp,_Tp> +mem_fun(_Sp (_Tp::*__f)() const) + {return const_mem_fun_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun1_t<_Sp,_Tp,_Ap> +mem_fun(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_ref_t + : public __unary_function<_Tp, _Sp> +{ + _Sp (_Tp::*__p_)() const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const + {return (__p.*__p_)();} +}; + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t + : public __binary_function<_Tp, _Ap, _Sp> +{ + _Sp (_Tp::*__p_)(_Ap) const; +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) + : __p_(__p) {} + _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const + {return (__p.*__p_)(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun_ref_t<_Sp,_Tp> +mem_fun_ref(_Sp (_Tp::*__f)() const) + {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +const_mem_fun1_ref_t<_Sp,_Tp,_Ap> +mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) + {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_MEM_FUN_REF_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/not_fn.h b/include/cuda/std/detail/libcxx/include/__functional/not_fn.h new file mode 100644 index 0000000000..302d80347a --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/not_fn.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_NOT_FN_H +#define _LIBCUDACXX___FUNCTIONAL_NOT_FN_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/invoke.h" +#include "../__functional/perfect_forward.h" +#include "../__type_traits/decay.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_move_constructible.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +struct __not_fn_op { + template + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const + noexcept(noexcept(!_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( !_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...)) + { return !_CUDA_VSTD::invoke(_CUDA_VSTD::forward<_Args>(__args)...); } +}; + +template +struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> { + using __perfect_forward<__not_fn_op, _Fn>::__perfect_forward; +}; + +template , _Fn> && + is_move_constructible_v> +>> +inline _LIBCUDACXX_INLINE_VISIBILITY +_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) { + return __not_fn_t>(_CUDA_VSTD::forward<_Fn>(__f)); +} + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_NOT_FN_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/operations.h b/include/cuda/std/detail/libcxx/include/__functional/operations.h new file mode 100644 index 0000000000..7dfd68d7b6 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/operations.h @@ -0,0 +1,584 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H +#define _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" +#include "../__functional/unary_function.h" +#include "../__utility/forward.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +// Arithmetic operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS plus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x + __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(plus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS plus +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS minus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x - __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(minus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS minus +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS multiplies + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x * __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(multiplies); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS multiplies +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS divides + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x / __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(divides); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS divides +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS modulus + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x % __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(modulus); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS modulus +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS negate + : __unary_function<_Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return -__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(negate); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS negate +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(- _CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( - _CUDA_VSTD::forward<_Tp>(__x)) + { return - _CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +// Bitwise operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_and + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x & __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_and); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_and +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +struct _LIBCUDACXX_TEMPLATE_VIS bit_not + : __unary_function<_Tp, _Tp> +{ + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x) const + {return ~__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_not); + +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_not +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(~_CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( ~_CUDA_VSTD::forward<_Tp>(__x)) + { return ~_CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_or + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x | __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_or); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_or +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS bit_xor + : __binary_function<_Tp, _Tp, _Tp> +{ + typedef _Tp __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + _Tp operator()(const _Tp& __x, const _Tp& __y) const + {return __x ^ __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_xor); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS bit_xor +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +// Comparison operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS equal_to + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x == __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(equal_to); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS equal_to +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x != __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(not_equal_to); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS less + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x < __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS less +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS less_equal + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x <= __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less_equal); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS less_equal +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS greater_equal + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x >= __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater_equal); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS greater_equal +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS greater + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x > __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS greater +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +// Logical operations + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_and + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x && __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_and); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_and +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_not + : __unary_function<_Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x) const + {return !__x;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_not); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_not +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_Tp&& __x) const + noexcept(noexcept(!_CUDA_VSTD::forward<_Tp>(__x))) + -> decltype( !_CUDA_VSTD::forward<_Tp>(__x)) + { return !_CUDA_VSTD::forward<_Tp>(__x); } + typedef void is_transparent; +}; +#endif + +#if _LIBCUDACXX_STD_VER > 11 +template +#else +template +#endif +struct _LIBCUDACXX_TEMPLATE_VIS logical_or + : __binary_function<_Tp, _Tp, bool> +{ + typedef bool __result_type; // used by valarray + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const _Tp& __x, const _Tp& __y) const + {return __x || __y;} +}; +_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_or); + +#if _LIBCUDACXX_STD_VER > 11 +template <> +struct _LIBCUDACXX_TEMPLATE_VIS logical_or +{ + template + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + auto operator()(_T1&& __t, _T2&& __u) const + noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u))) + -> decltype( _CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u)) + { return _CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u); } + typedef void is_transparent; +}; +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_OPERATIONS_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h b/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h new file mode 100644 index 0000000000..8d1abcd63e --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/perfect_forward.h @@ -0,0 +1,113 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H +#define _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__concepts/__concept_macros.h" +#include "../__functional/invoke.h" +#include "../__type_traits/enable_if.h" +#include "../__type_traits/is_constructible.h" +#include "../__type_traits/is_nothrow_constructible.h" +#include "../__utility/declval.h" +#include "../__utility/forward.h" +#include "../__utility/integer_sequence.h" +#include "../__utility/move.h" + +#include "../tuple" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER > 14 + +template +struct __perfect_forward_impl; + +template +struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> { +private: + tuple<_BoundArgs...> __bound_args_; + +public: + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_constructible_v, _Args&&...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY + explicit constexpr __perfect_forward_impl(_Args&&... __bound_args) + noexcept(is_nothrow_constructible_v, _Args&&...>) + : __bound_args_(_CUDA_VSTD::forward<_Args>(__bound_args)...) {} + + __perfect_forward_impl(__perfect_forward_impl const&) = default; + __perfect_forward_impl(__perfect_forward_impl&&) = default; + + __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default; + __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs&..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) & + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) & = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs const&..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const& + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(__bound_args_)..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs const&..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) const& = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) && + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) && = delete; + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires is_invocable_v<_Op, _BoundArgs const..., _Args...>) + _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&& + noexcept(noexcept(_Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...))) + -> decltype( _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...)) + { return _Op()(_CUDA_VSTD::get<_Idx>(_CUDA_VSTD::move(__bound_args_))..., _CUDA_VSTD::forward<_Args>(__args)...); } + + _LIBCUDACXX_TEMPLATE(class... _Args) + (requires (!is_invocable_v<_Op, _BoundArgs const..., _Args...>)) + _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_Args&&...) const&& = delete; +}; + +// __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require]. +template +using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>; + +#endif // _LIBCUDACXX_STD_VER > 14 + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_PERFECT_FORWARD_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h b/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h new file mode 100644 index 0000000000..eeb6ce7928 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/pointer_to_binary_function.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/binary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_binary_function + : public __binary_function<_Arg1, _Arg2, _Result> +{ + _Result (*__f_)(_Arg1, _Arg2); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) + : __f_(__f) {} + _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const + {return __f_(__x, __y);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +pointer_to_binary_function<_Arg1,_Arg2,_Result> +ptr_fun(_Result (*__f)(_Arg1,_Arg2)) + {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} + +#endif + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_POINTER_TO_BINARY_FUNCTION_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h b/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h new file mode 100644 index 0000000000..da00ac97ec --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/pointer_to_unary_function.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H +#define _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_unary_function + : public __unary_function<_Arg, _Result> +{ + _Result (*__f_)(_Arg); +public: + _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) + : __f_(__f) {} + _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg __x) const + {return __f_(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY +pointer_to_unary_function<_Arg,_Result> +ptr_fun(_Result (*__f)(_Arg)) + {return pointer_to_unary_function<_Arg,_Result>(__f);} + +#endif // _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_POINTER_TO_UNARY_FUNCTION_H diff --git a/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h b/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h new file mode 100644 index 0000000000..087d5921e9 --- /dev/null +++ b/include/cuda/std/detail/libcxx/include/__functional/unary_negate.h @@ -0,0 +1,51 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H +#define _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H + +#ifndef __cuda_std__ +#include <__config> +#endif // __cuda_std__ + +#include "../__functional/unary_function.h" + +#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +#if _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +template +class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 unary_negate + : public __unary_function +{ + _Predicate __pred_; +public: + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + explicit unary_negate(const _Predicate& __pred) + : __pred_(__pred) {} + _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY + bool operator()(const typename _Predicate::argument_type& __x) const + {return !__pred_(__x);} +}; + +template +_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY +unary_negate<_Predicate> +not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} + +#endif // _LIBCUDACXX_STD_VER <= 17 || defined(_LIBCUDACXX_ENABLE_CXX20_REMOVED_NEGATORS) + +_LIBCUDACXX_END_NAMESPACE_STD + +#endif // _LIBCUDACXX___FUNCTIONAL_UNARY_NEGATE_H diff --git a/include/cuda/std/detail/libcxx/include/__functional_base b/include/cuda/std/detail/libcxx/include/__functional_base index 260bbaaef5..6d30d01429 100644 --- a/include/cuda/std/detail/libcxx/include/__functional_base +++ b/include/cuda/std/detail/libcxx/include/__functional_base @@ -12,22 +12,19 @@ #ifndef __cuda_std__ #include <__config> -#include <__functional/binary_function.h> -#include <__functional/reference_wrapper.h> -#include <__functional/unary_function.h> -#include <__functional/weak_result_type.h> #include #include #include #include #include #include <__pragma_push> -#else +#endif //__cuda_std__ + #include "__functional/binary_function.h" +#include "__functional/operations.h" #include "__functional/reference_wrapper.h" #include "__functional/unary_function.h" #include "__functional/weak_result_type.h" -#endif //__cuda_std__ #if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) #pragma GCC system_header @@ -35,48 +32,12 @@ _LIBCUDACXX_BEGIN_NAMESPACE_STD -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x < __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS less -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - #ifdef _LIBCUDACXX_CXX03_LANG #include <__functional_base_03> #endif // !defined(_LIBCUDACXX_CXX03_LANG) -#if _LIBCUDACXX_STD_VER > 11 -template -struct __is_transparent : false_type {}; - -template -struct __is_transparent<_Tp, _Up, - __void_t> - : true_type {}; -#endif - // allocator_arg_t struct _LIBCUDACXX_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; }; diff --git a/include/cuda/std/detail/libcxx/include/__utility/pair.h b/include/cuda/std/detail/libcxx/include/__utility/pair.h index 44f5b9690a..6f91ff697b 100644 --- a/include/cuda/std/detail/libcxx/include/__utility/pair.h +++ b/include/cuda/std/detail/libcxx/include/__utility/pair.h @@ -84,65 +84,41 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair pair(pair const&) = default; pair(pair&&) = default; -#ifdef _LIBCUDACXX_CXX03_LANG - _LIBCUDACXX_INLINE_VISIBILITY - pair() : first(), second() {} - - _LIBCUDACXX_INLINE_VISIBILITY - pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {} - - _LIBCUDACXX_INLINE_VISIBILITY - pair& operator=(pair const& __p) { - first = __p.first; - second = __p.second; - return *this; - } -#else struct _CheckArgs { - template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_explicit_default() { - return is_default_constructible<_T1>::value - && is_default_constructible<_T2>::value - && !__enable_implicit_default<>(); - } + struct __enable_implicit_default : public integral_constant::value + && __is_implicitly_default_constructible<_T2>::value> + {}; - template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_implicit_default() { - return __is_implicitly_default_constructible<_T1>::value - && __is_implicitly_default_constructible<_T2>::value; - } + struct __enable_explicit_default : public integral_constant::value + && is_default_constructible<_T2>::value + && !__enable_implicit_default::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __is_pair_constructible() { - return is_constructible::value - && is_constructible::value; - } + struct __is_pair_constructible : public integral_constant::value + && is_constructible::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __is_implicit() { - return is_convertible<_U1, first_type>::value - && is_convertible<_U2, second_type>::value; - } + struct __is_implicit : public integral_constant::value + && is_convertible<_U2, second_type>::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_explicit() { - return __is_pair_constructible<_U1, _U2>() && !__is_implicit<_U1, _U2>(); - } + struct __enable_explicit : public integral_constant::value + && !__is_implicit<_U1, _U2>::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_implicit() { - return __is_pair_constructible<_U1, _U2>() && __is_implicit<_U1, _U2>(); - } + struct __enable_implicit : public integral_constant::value + && __is_implicit<_U1, _U2>::value> + {}; }; template @@ -151,23 +127,18 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair struct _CheckTupleLikeConstructor { template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_implicit() { - return __tuple_convertible<_Tuple, pair>::value; - } - + struct __enable_implicit : public integral_constant::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_explicit() { - return __tuple_constructible<_Tuple, pair>::value - && !__tuple_convertible<_Tuple, pair>::value; - } - + struct __enable_explicit : public integral_constant::value + && !__tuple_convertible<_Tuple, pair>::value> + {}; template - _LIBCUDACXX_INLINE_VISIBILITY - static constexpr bool __enable_assign() { - return __tuple_assignable<_Tuple, pair>::value; - } + struct __enable_assign : public integral_constant::value> + {}; }; template @@ -179,7 +150,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair >; template::__enable_explicit_default() + _CheckArgsDep<_Dummy>::__enable_explicit_default::value >* = nullptr> explicit _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR pair() _NOEXCEPT_(is_nothrow_default_constructible::value && @@ -187,7 +158,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(), second() {} template::__enable_implicit_default() + _CheckArgsDep<_Dummy>::__enable_implicit_default::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR pair() _NOEXCEPT_(is_nothrow_default_constructible::value && @@ -195,7 +166,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(), second() {} template ::template __enable_explicit<_T1 const&, _T2 const&>() + _CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit pair(_T1 const& __t1, _T2 const& __t2) @@ -204,7 +175,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(__t1), second(__t2) {} template::template __enable_implicit<_T1 const&, _T2 const&>() + _CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair(_T1 const& __t1, _T2 const& __t2) @@ -218,7 +189,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair #else class _U1, class _U2, #endif - __enable_if_t<_CheckArgs::template __enable_explicit<_U1, _U2>()>* = nullptr + __enable_if_t<_CheckArgs::template __enable_explicit<_U1, _U2>::value>* = nullptr > _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit pair(_U1&& __u1, _U2&& __u2) @@ -232,7 +203,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair #else class _U1, class _U2, #endif - __enable_if_t<_CheckArgs::template __enable_implicit<_U1, _U2>()>* = nullptr + __enable_if_t<_CheckArgs::template __enable_implicit<_U1, _U2>::value>* = nullptr > _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair(_U1&& __u1, _U2&& __u2) @@ -242,17 +213,17 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair #if _LIBCUDACXX_STD_VER > 20 template() + _CheckArgs::template __is_pair_constructible<_U1&, _U2&>::value >* = nullptr> _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr explicit(!_CheckArgs::template __is_implicit<_U1&, _U2&>()) pair(pair<_U1, _U2>& __p) noexcept((is_nothrow_constructible::value && is_nothrow_constructible::value)) : first(__p.first), second(__p.second) {} -#endif +#endif // _LIBCUDACXX_STD_VER > 20 template() + _CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit pair(pair<_U1, _U2> const& __p) @@ -261,7 +232,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(__p.first), second(__p.second) {} template() + _CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair(pair<_U1, _U2> const& __p) @@ -270,7 +241,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(__p.first), second(__p.second) {} template() + _CheckArgs::template __enable_explicit<_U1, _U2>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit pair(pair<_U1, _U2>&&__p) @@ -279,7 +250,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair : first(_CUDA_VSTD::forward<_U1>(__p.first)), second(_CUDA_VSTD::forward<_U2>(__p.second)) {} template() + _CheckArgs::template __enable_implicit<_U1, _U2>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair(pair<_U1, _U2>&& __p) @@ -289,18 +260,18 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair #if _LIBCUDACXX_STD_VER > 20 template() + _CheckArgs::template __is_pair_constructible::value >* = nullptr> _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr - explicit(!_CheckArgs::template __is_implicit()) + explicit(!_CheckArgs::template __is_implicit::value) pair(const pair<_U1, _U2>&& __p) noexcept(is_nothrow_constructible::value && is_nothrow_constructible::value) : first(_CUDA_VSTD::move(__p.first)), second(_CUDA_VSTD::move(__p.second)) {} -#endif +#endif // _LIBCUDACXX_STD_VER > 20 template::template __enable_explicit<_Tuple>() + _CheckTLC<_Tuple>::template __enable_explicit<_Tuple>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 explicit pair(_Tuple&& __p) @@ -308,7 +279,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair second(_CUDA_VSTD::get<1>(_CUDA_VSTD::forward<_Tuple>(__p))) {} template::template __enable_implicit<_Tuple>() + _CheckTLC<_Tuple>::template __enable_implicit<_Tuple>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair(_Tuple&& __p) @@ -396,7 +367,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair #endif // _LIBCUDACXX_STD_VER > 20 template ::template __enable_assign<_Tuple>() + _CheckTLC<_Tuple>::template __enable_assign<_Tuple>::value >* = nullptr> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 pair& operator=(_Tuple&& __p) { @@ -404,12 +375,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair second = _CUDA_VSTD::get<1>(_CUDA_VSTD::forward<_Tuple>(__p)); return *this; } -#endif _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 - void - swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable::value && - __is_nothrow_swappable::value) + void swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable::value && + __is_nothrow_swappable::value) { using _CUDA_VSTD::swap; swap(first, __p.first); @@ -426,22 +395,21 @@ struct _LIBCUDACXX_TEMPLATE_VIS pair swap(first, __p.first); swap(second, __p.second); } -#endif +#endif // _LIBCUDACXX_STD_VER > 20 + private: -#ifndef _LIBCUDACXX_CXX03_LANG template _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 pair(piecewise_construct_t, tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args, __tuple_indices<_I1...>, __tuple_indices<_I2...>); -#endif }; -#if _LIBCUDACXX_STD_VER > 14 +#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) template pair(_T1, _T2) -> pair<_T1, _T2>; -#endif +#endif // _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES) // [pairs.spec], specialized algorithms @@ -553,9 +521,8 @@ void swap(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) { __x.swap(__y); } -#endif +#endif // _LIBCUDACXX_STD_VER > 20 -#ifndef _LIBCUDACXX_CXX03_LANG template inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 pair::type, typename __unwrap_ref_decay<_T2>::type> @@ -565,18 +532,6 @@ make_pair(_T1&& __t1, _T2&& __t2) (_CUDA_VSTD::forward<_T1>(__t1), _CUDA_VSTD::forward<_T2>(__t2)); } -#else // _LIBCUDACXX_CXX03_LANG - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -pair<_T1,_T2> -make_pair(_T1 __x, _T2 __y) -{ - return pair<_T1, _T2>(__x, __y); -} - -#endif // _LIBCUDACXX_CXX03_LANG - template struct _LIBCUDACXX_TEMPLATE_VIS tuple_size > : public integral_constant {}; @@ -616,7 +571,6 @@ struct __get_pair<0> const _T1& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;} -#ifndef _LIBCUDACXX_CXX03_LANG template static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 @@ -628,7 +582,6 @@ struct __get_pair<0> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const _T1&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _CUDA_VSTD::forward(__p.first);} -#endif // _LIBCUDACXX_CXX03_LANG }; template <> @@ -646,7 +599,6 @@ struct __get_pair<1> const _T2& get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;} -#ifndef _LIBCUDACXX_CXX03_LANG template static _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 @@ -658,7 +610,6 @@ struct __get_pair<1> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const _T2&& get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _CUDA_VSTD::forward(__p.second);} -#endif // _LIBCUDACXX_CXX03_LANG }; template @@ -677,7 +628,6 @@ get(const pair<_T1, _T2>& __p) _NOEXCEPT return __get_pair<_Ip>::get(__p); } -#ifndef _LIBCUDACXX_CXX03_LANG template inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& @@ -693,7 +643,6 @@ get(const pair<_T1, _T2>&& __p) _NOEXCEPT { return __get_pair<_Ip>::get(_CUDA_VSTD::move(__p)); } -#endif // _LIBCUDACXX_CXX03_LANG #if _LIBCUDACXX_STD_VER > 11 template diff --git a/include/cuda/std/detail/libcxx/include/__utility/unreachable.h b/include/cuda/std/detail/libcxx/include/__utility/unreachable.h index 21d6f2329f..50a207cd11 100644 --- a/include/cuda/std/detail/libcxx/include/__utility/unreachable.h +++ b/include/cuda/std/detail/libcxx/include/__utility/unreachable.h @@ -12,13 +12,14 @@ #ifndef __cuda_std__ #include <__config> +#include #endif // __cuda_std__ + #if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) #pragma GCC system_header #endif -#ifndef _LIBCUDACXX_UNREACHABLE #ifdef __GNUC__ # define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() #elif __has_builtin(__builtin_unreachable) @@ -27,10 +28,9 @@ #ifdef __CUDA_ARCH__ # define _LIBCUDACXX_UNREACHABLE() __trap() #else -# define _LIBCUDACXX_UNREACHABLE() _CUDA_VSTD::abort() -#endif -#endif // has_builtin -#endif // !_LIBCUDACXX_UNREACHABLE +# define _LIBCUDACXX_UNREACHABLE() ::abort() +#endif // __CUDA_ARCH__ +#endif // !__GNUC__ _LIBCUDACXX_BEGIN_NAMESPACE_STD diff --git a/include/cuda/std/detail/libcxx/include/algorithm b/include/cuda/std/detail/libcxx/include/algorithm index b5f745c151..9b4124f873 100644 --- a/include/cuda/std/detail/libcxx/include/algorithm +++ b/include/cuda/std/detail/libcxx/include/algorithm @@ -1358,9 +1358,9 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, return true; // __first1 != __last1 && *__first1 != *__first2 - typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; - _D1 __l1 = _CUDA_VSTD::distance(__first1, __last1); - if (__l1 == _D1(1)) + typedef typename iterator_traits<_ForwardIterator1>::difference_type _Diff1; + _Diff1 __l1 = _CUDA_VSTD::distance(__first1, __last1); + if (__l1 == _Diff1(1)) return false; _ForwardIterator2 __last2 = _CUDA_VSTD::next(__first2, __l1); // For each element in [f1, l1) see if there are the same number of @@ -1374,14 +1374,14 @@ is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, break; if (__match == __i) { // Count number of *__i in [f2, l2) - _D1 __c2 = 0; + _Diff1 __c2 = 0; for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) if (__pred(*__i, *__j)) ++__c2; if (__c2 == 0) return false; // Count number of *__i in [__i, l1) (we can start with 1) - _D1 __c1 = 1; + _Diff1 __c1 = 1; for (_ForwardIterator1 __j = _CUDA_VSTD::next(__i); __j != __last1; ++__j) if (__pred(*__i, *__j)) ++__c1; @@ -1422,11 +1422,11 @@ __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, else if (__first2 == __last2) return false; - typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1; - _D1 __l1 = _CUDA_VSTD::distance(__first1, __last1); + typedef typename iterator_traits<_ForwardIterator1>::difference_type _Diff1; + _Diff1 __l1 = _CUDA_VSTD::distance(__first1, __last1); - typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2; - _D2 __l2 = _CUDA_VSTD::distance(__first2, __last2); + typedef typename iterator_traits<_ForwardIterator2>::difference_type _Diff2; + __Diff2 __l2 = _CUDA_VSTD::distance(__first2, __last2); if (__l1 != __l2) return false; @@ -1441,14 +1441,14 @@ __is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, break; if (__match == __i) { // Count number of *__i in [f2, l2) - _D1 __c2 = 0; + _Diff1 __c2 = 0; for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j) if (__pred(*__i, *__j)) ++__c2; if (__c2 == 0) return false; // Count number of *__i in [__i, l1) (we can start with 1) - _D1 __c1 = 1; + _Diff1 __c1 = 1; for (_ForwardIterator1 __j = _CUDA_VSTD::next(__i); __j != __last1; ++__j) if (__pred(*__i, *__j)) ++__c1; diff --git a/include/cuda/std/detail/libcxx/include/cstdlib b/include/cuda/std/detail/libcxx/include/cstdlib index a6be52c9a6..6a89b41fe4 100644 --- a/include/cuda/std/detail/libcxx/include/cstdlib +++ b/include/cuda/std/detail/libcxx/include/cstdlib @@ -92,14 +92,16 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #endif #ifdef __GNUC__ -#define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() +# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() +#elif __has_builtin(__builtin_unreachable) +# define _LIBCUDACXX_UNREACHABLE() __builtin_unreachable() #else -#if defined(__CUDA_ARCH__) +#ifdef __CUDA_ARCH__ # define _LIBCUDACXX_UNREACHABLE() __trap() #else -# define _LIBCUDACXX_UNREACHABLE() _CUDA_VSTD::abort() -#endif -#endif +# define _LIBCUDACXX_UNREACHABLE() ::abort() +#endif // __CUDA_ARCH__ +#endif // !__GNUC__ #ifdef _LIBCUDACXX_COMPILER_PGI #define _LIBCUDACXX_UNREACHABLE_AFTER_SWITCH() diff --git a/include/cuda/std/detail/libcxx/include/deque b/include/cuda/std/detail/libcxx/include/deque index a1af54e0c7..37074e177f 100644 --- a/include/cuda/std/detail/libcxx/include/deque +++ b/include/cuda/std/detail/libcxx/include/deque @@ -185,92 +185,92 @@ template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); -template _OutputIterator -copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); -template _OutputIterator -copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); -template _OutputIterator -move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); -template _OutputIterator -move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template struct __deque_block_size { @@ -444,104 +444,104 @@ private: friend class _LIBCUDACXX_TEMPLATE_VIS __deque_iterator; template + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); - template friend _OutputIterator - copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); - template + template friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> - copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> + copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); - template friend _OutputIterator - copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); - template + template friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> - copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> + copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); - template friend _OutputIterator - move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); - template + template friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> - move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> + move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); template + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*); - template friend _OutputIterator - move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r); - template + template friend - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> - move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> + move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r); }; template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) { - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; @@ -582,16 +582,16 @@ copy(_RAIter __f, return __r; } -template _OutputIterator -copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { @@ -610,16 +610,16 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, return __r; } -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +copy(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { @@ -641,18 +641,18 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, // copy_backward template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> copy_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) { - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::pointer pointer; while (__f != __l) { - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _CUDA_VSTD::prev(__r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __rp = _CUDA_VSTD::prev(__r); pointer __rb = *__rp.__m_iter_; pointer __re = __rp.__ptr_ + 1; difference_type __bs = __re - __rb; @@ -670,15 +670,15 @@ copy_backward(_RAIter __f, return __r; } -template _OutputIterator -copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { @@ -698,15 +698,15 @@ copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, return __r; } -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { @@ -729,16 +729,16 @@ copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, // move template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) { - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; @@ -758,16 +758,16 @@ move(_RAIter __f, return __r; } -template _OutputIterator -move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { @@ -786,16 +786,16 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, return __r; } -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +move(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; - const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { @@ -817,18 +817,18 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, // move_backward template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> + class _V2, class _P2, class _R2, class _M2, class _Diff2, _Diff2 _B2> +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> move_backward(_RAIter __f, _RAIter __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r, typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) { - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; - typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::difference_type difference_type; + typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2>::pointer pointer; while (__f != __l) { - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _CUDA_VSTD::prev(__r); + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __rp = _CUDA_VSTD::prev(__r); pointer __rb = *__rp.__m_iter_; pointer __re = __rp.__ptr_ + 1; difference_type __bs = __re - __rb; @@ -846,15 +846,15 @@ move_backward(_RAIter __f, return __r; } -template _OutputIterator -move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, _OutputIterator __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { @@ -874,15 +874,15 @@ move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, return __r; } -template -__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> -move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, - __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, - __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) +template +__deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> +move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __f, + __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1> __l, + __deque_iterator<_V2, _P2, _R2, _M2, _Diff2, _B2> __r) { - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; - typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::difference_type difference_type; + typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _Diff1, _B1>::pointer pointer; difference_type __n = __l - __f; while (__n > 0) { diff --git a/include/cuda/std/detail/libcxx/include/functional b/include/cuda/std/detail/libcxx/include/functional index 81e3375f18..29b7425411 100644 --- a/include/cuda/std/detail/libcxx/include/functional +++ b/include/cuda/std/detail/libcxx/include/functional @@ -499,2606 +499,38 @@ POLICY: For non-variadic implementations, the number of arguments is limited #ifndef __cuda_std__ #include <__config> -#include -#include -#include -#include -#include -#include #include -#include <__functional_base> -#include <__pragma_push> #endif // __cuda_std__ #include "__functional/binary_function.h" +#include "__functional/binary_negate.h" +#include "__functional/bind_back.h" +#include "__functional/bind_front.h" +#include "__functional/bind.h" +#include "__functional/binder1st.h" +#include "__functional/binder2nd.h" +#include "__functional/compose.h" +#include "__functional/default_searcher.h" +#include "__functional/function.h" #include "__functional/hash.h" #include "__functional/identity.h" #include "__functional/invoke.h" +#include "__functional/is_transparent.h" +#include "__functional/mem_fn.h" +#include "__functional/mem_fun_ref.h" +#include "__functional/not_fn.h" +#include "__functional/operations.h" +#include "__functional/perfect_forward.h" +#include "__functional/pointer_to_binary_function.h" +#include "__functional/pointer_to_unary_function.h" #include "__functional/reference_wrapper.h" #include "__functional/unary_function.h" +#include "__functional/unary_negate.h" #include "__functional/unwrap_ref.h" #include "__functional/weak_result_type.h" -#include "__memory/addressof.h" -#include "__memory/pointer_traits.h" #if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER) #pragma GCC system_header #endif -_LIBCUDACXX_BEGIN_NAMESPACE_STD - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x + __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS plus -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x - __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS minus -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x * __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS multiplies -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x / __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS divides -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x % __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS modulus -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x) const - {return -__x;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS negate -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Tp&& __x) const - _NOEXCEPT_(noexcept(- _CUDA_VSTD::forward<_Tp>(__x))) - -> decltype (- _CUDA_VSTD::forward<_Tp>(__x)) - { return - _CUDA_VSTD::forward<_Tp>(__x); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x == __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS equal_to -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x != __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x > __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS greater -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -// less in <__functional_base> - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x >= __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS greater_equal -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x <= __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS less_equal -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x && __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS logical_and -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x, const _Tp& __y) const - {return __x || __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS logical_or -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const _Tp& __x) const - {return !__x;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS logical_not -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Tp&& __x) const - _NOEXCEPT_(noexcept(!_CUDA_VSTD::forward<_Tp>(__x))) - -> decltype (!_CUDA_VSTD::forward<_Tp>(__x)) - { return !_CUDA_VSTD::forward<_Tp>(__x); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x & __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS bit_and -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x | __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS bit_or -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -#else -template -#endif -struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x, const _Tp& __y) const - {return __x ^ __y;} -}; - -#if _LIBCUDACXX_STD_VER > 11 -template <> -struct _LIBCUDACXX_TEMPLATE_VIS bit_xor -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_T1&& __t, _T2&& __u) const - _NOEXCEPT_(noexcept(_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u))) - -> decltype (_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u)) - { return _CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u); } - typedef void is_transparent; -}; -#endif - - -#if _LIBCUDACXX_STD_VER > 11 -template -struct _LIBCUDACXX_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp> -{ - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - _Tp operator()(const _Tp& __x) const - {return ~__x;} -}; - -template <> -struct _LIBCUDACXX_TEMPLATE_VIS bit_not -{ - template - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Tp&& __x) const - _NOEXCEPT_(noexcept(~_CUDA_VSTD::forward<_Tp>(__x))) - -> decltype (~_CUDA_VSTD::forward<_Tp>(__x)) - { return ~_CUDA_VSTD::forward<_Tp>(__x); } - typedef void is_transparent; -}; -#endif - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 unary_negate - : public __unary_function -{ - _Predicate __pred_; -public: - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - explicit unary_negate(const _Predicate& __pred) - : __pred_(__pred) {} - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const typename _Predicate::argument_type& __x) const - {return !__pred_(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY -unary_negate<_Predicate> -not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX17 binary_negate - : public __binary_function -{ - _Predicate __pred_; -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 - binary_negate(const _Predicate& __pred) : __pred_(__pred) {} - - _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY - bool operator()(const typename _Predicate::first_argument_type& __x, - const typename _Predicate::second_argument_type& __y) const - {return !__pred_(__x, __y);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX17 inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY -binary_negate<_Predicate> -not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} - -#if _LIBCUDACXX_STD_VER <= 14 || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_BINDERS) -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder1st - : public __unary_function -{ -protected: - __Operation op; - typename __Operation::first_argument_type value; -public: - _LIBCUDACXX_INLINE_VISIBILITY binder1st(const __Operation& __x, - const typename __Operation::first_argument_type __y) - : op(__x), value(__y) {} - _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() - (typename __Operation::second_argument_type& __x) const - {return op(value, __x);} - _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() - (const typename __Operation::second_argument_type& __x) const - {return op(value, __x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -binder1st<__Operation> -bind1st(const __Operation& __op, const _Tp& __x) - {return binder1st<__Operation>(__op, __x);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 binder2nd - : public __unary_function -{ -protected: - __Operation op; - typename __Operation::second_argument_type value; -public: - _LIBCUDACXX_INLINE_VISIBILITY - binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) - : op(__x), value(__y) {} - _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() - ( typename __Operation::first_argument_type& __x) const - {return op(__x, value);} - _LIBCUDACXX_INLINE_VISIBILITY typename __Operation::result_type operator() - (const typename __Operation::first_argument_type& __x) const - {return op(__x, value);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -binder2nd<__Operation> -bind2nd(const __Operation& __op, const _Tp& __x) - {return binder2nd<__Operation>(__op, __x);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_unary_function - : public __unary_function<_Arg, _Result> -{ - _Result (*__f_)(_Arg); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) - : __f_(__f) {} - _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg __x) const - {return __f_(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -pointer_to_unary_function<_Arg,_Result> -ptr_fun(_Result (*__f)(_Arg)) - {return pointer_to_unary_function<_Arg,_Result>(__f);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 pointer_to_binary_function - : public __binary_function<_Arg1, _Arg2, _Result> -{ - _Result (*__f_)(_Arg1, _Arg2); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) - : __f_(__f) {} - _LIBCUDACXX_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const - {return __f_(__x, __y);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -pointer_to_binary_function<_Arg1,_Arg2,_Result> -ptr_fun(_Result (*__f)(_Arg1,_Arg2)) - {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_t - : public __unary_function<_Tp*, _Sp> -{ - _Sp (_Tp::*__p_)(); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const - {return (__p->*__p_)();} -}; - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_t - : public __binary_function<_Tp*, _Ap, _Sp> -{ - _Sp (_Tp::*__p_)(_Ap); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const - {return (__p->*__p_)(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -mem_fun_t<_Sp,_Tp> -mem_fun(_Sp (_Tp::*__f)()) - {return mem_fun_t<_Sp,_Tp>(__f);} - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -mem_fun1_t<_Sp,_Tp,_Ap> -mem_fun(_Sp (_Tp::*__f)(_Ap)) - {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun_ref_t - : public __unary_function<_Tp, _Sp> -{ - _Sp (_Tp::*__p_)(); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const - {return (__p.*__p_)();} -}; - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 mem_fun1_ref_t - : public __binary_function<_Tp, _Ap, _Sp> -{ - _Sp (_Tp::*__p_)(_Ap); -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const - {return (__p.*__p_)(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -mem_fun_ref_t<_Sp,_Tp> -mem_fun_ref(_Sp (_Tp::*__f)()) - {return mem_fun_ref_t<_Sp,_Tp>(__f);} - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -mem_fun1_ref_t<_Sp,_Tp,_Ap> -mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) - {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_t - : public __unary_function -{ - _Sp (_Tp::*__p_)() const; -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const - {return (__p->*__p_)();} -}; - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_t - : public __binary_function -{ - _Sp (_Tp::*__p_)(_Ap) const; -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const - {return (__p->*__p_)(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -const_mem_fun_t<_Sp,_Tp> -mem_fun(_Sp (_Tp::*__f)() const) - {return const_mem_fun_t<_Sp,_Tp>(__f);} - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -const_mem_fun1_t<_Sp,_Tp,_Ap> -mem_fun(_Sp (_Tp::*__f)(_Ap) const) - {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun_ref_t - : public __unary_function<_Tp, _Sp> -{ - _Sp (_Tp::*__p_)() const; -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const - {return (__p.*__p_)();} -}; - -template -class _LIBCUDACXX_TEMPLATE_VIS _LIBCUDACXX_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t - : public __binary_function<_Tp, _Ap, _Sp> -{ - _Sp (_Tp::*__p_)(_Ap) const; -public: - _LIBCUDACXX_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) - : __p_(__p) {} - _LIBCUDACXX_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const - {return (__p.*__p_)(__x);} -}; - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -const_mem_fun_ref_t<_Sp,_Tp> -mem_fun_ref(_Sp (_Tp::*__f)() const) - {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} - -template -_LIBCUDACXX_DEPRECATED_IN_CXX11 inline _LIBCUDACXX_INLINE_VISIBILITY -const_mem_fun1_ref_t<_Sp,_Tp,_Ap> -mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) - {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} -#endif - -//////////////////////////////////////////////////////////////////////////////// -// MEMFUN -//============================================================================== - -template -class __mem_fn - : public __weak_result_type<_Tp> -{ -public: - // types - typedef _Tp type; -private: - type __f_; - -public: - _LIBCUDACXX_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} - -#ifndef _LIBCUDACXX_CXX03_LANG - // invoke - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return::type - operator() (_ArgTypes&&... __args) const { - return __invoke(__f_, _CUDA_VSTD::forward<_ArgTypes>(__args)...); - } -#else - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return0::type - operator() (_A0& __a0) const { - return __invoke(__f_, __a0); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return0::type - operator() (_A0 const& __a0) const { - return __invoke(__f_, __a0); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return1::type - operator() (_A0& __a0, _A1& __a1) const { - return __invoke(__f_, __a0, __a1); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return1::type - operator() (_A0 const& __a0, _A1& __a1) const { - return __invoke(__f_, __a0, __a1); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return1::type - operator() (_A0& __a0, _A1 const& __a1) const { - return __invoke(__f_, __a0, __a1); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return1::type - operator() (_A0 const& __a0, _A1 const& __a1) const { - return __invoke(__f_, __a0, __a1); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __invoke_return2::type - operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { - return __invoke(__f_, __a0, __a1, __a2); - } -#endif -}; - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -__mem_fn<_Rp _Tp::*> -mem_fn(_Rp _Tp::* __pm) _NOEXCEPT -{ - return __mem_fn<_Rp _Tp::*>(__pm); -} - -// `cuda::std::function` is not supported at this time. - -#ifndef __cuda_std__ - -//////////////////////////////////////////////////////////////////////////////// -// FUNCTION -//============================================================================== - -// bad_function_call - -class _LIBCUDACXX_EXCEPTION_ABI bad_function_call - : public exception -{ -#ifdef _LIBCUDACXX_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION -public: - virtual ~bad_function_call() _NOEXCEPT; - - virtual const char* what() const _NOEXCEPT; -#endif -}; - -_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY -void __throw_bad_function_call() -{ -#ifndef _LIBCUDACXX_NO_EXCEPTIONS - throw bad_function_call(); -#else - _CUDA_VSTD::abort(); -#endif -} - -template class _LIBCUDACXX_TEMPLATE_VIS function; // undefined - -namespace __function -{ - -template -struct __maybe_derive_from_unary_function -{ -}; - -template -struct __maybe_derive_from_unary_function<_Rp(_A1)> - : public __unary_function<_A1, _Rp> -{ -}; - -template -struct __maybe_derive_from_binary_function -{ -}; - -template -struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> - : public __binary_function<_A1, _A2, _Rp> -{ -}; - -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __not_null(_Fp const&) { return true; } - -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __not_null(_Fp* __ptr) { return __ptr; } - -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __not_null(_Ret _Class::*__ptr) { return __ptr; } - -template -_LIBCUDACXX_INLINE_VISIBILITY -bool __not_null(function<_Fp> const& __f) { return !!__f; } - -} // namespace __function - -#ifndef _LIBCUDACXX_CXX03_LANG - -namespace __function { - -// __alloc_func holds a functor and an allocator. - -template class __alloc_func; -template -class __default_alloc_func; - -template -class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> -{ - __compressed_pair<_Fp, _Ap> __f_; - - public: - typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; - typedef _LIBCUDACXX_NODEBUG_TYPE _Ap _Alloc; - - _LIBCUDACXX_INLINE_VISIBILITY - const _Target& __target() const { return __f_.first(); } - - // WIN32 APIs may define __allocator, so use __get_allocator instead. - _LIBCUDACXX_INLINE_VISIBILITY - const _Alloc& __get_allocator() const { return __f_.second(); } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __alloc_func(_Target&& __f) - : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), - _CUDA_VSTD::forward_as_tuple()) - { - } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __alloc_func(const _Target& __f, const _Alloc& __a) - : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), - _CUDA_VSTD::forward_as_tuple(__a)) - { - } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __alloc_func(const _Target& __f, _Alloc&& __a) - : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(__f), - _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) - { - } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __alloc_func(_Target&& __f, _Alloc&& __a) - : __f_(piecewise_construct, _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__f)), - _CUDA_VSTD::forward_as_tuple(_CUDA_VSTD::move(__a))) - { - } - - _LIBCUDACXX_INLINE_VISIBILITY - _Rp operator()(_ArgTypes&&... __arg) - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_.first(), - _CUDA_VSTD::forward<_ArgTypes>(__arg)...); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __alloc_func* __clone() const - { - typedef allocator_traits<_Alloc> __alloc_traits; - typedef - typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _AA; - _AA __a(__f_.second()); - typedef __allocator_destructor<_AA> _Dp; - unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); - return __hold.release(); - } - - _LIBCUDACXX_INLINE_VISIBILITY - void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } - - static void __destroy_and_delete(__alloc_func* __f) { - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _FunAlloc; - _FunAlloc __a(__f->__get_allocator()); - __f->destroy(); - __a.deallocate(__f, 1); - } -}; - -template -class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { - _Fp __f_; - -public: - typedef _LIBCUDACXX_NODEBUG_TYPE _Fp _Target; - - _LIBCUDACXX_INLINE_VISIBILITY - const _Target& __target() const { return __f_; } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __default_alloc_func(_Target&& __f) : __f_(std::move(__f)) {} - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} - - _LIBCUDACXX_INLINE_VISIBILITY - _Rp operator()(_ArgTypes&&... __arg) { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(__f_, _CUDA_VSTD::forward<_ArgTypes>(__arg)...); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __default_alloc_func* __clone() const { - __builtin_new_allocator::__holder_t __hold = - __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); - __default_alloc_func* __res = - ::new (__hold.get()) __default_alloc_func(__f_); - (void)__hold.release(); - return __res; - } - - _LIBCUDACXX_INLINE_VISIBILITY - void destroy() _NOEXCEPT { __f_.~_Target(); } - - static void __destroy_and_delete(__default_alloc_func* __f) { - __f->destroy(); - __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); - } -}; - -// __base provides an abstract interface for copyable functors. - -template class __base; - -template -class __base<_Rp(_ArgTypes...)> -{ - __base(const __base&); - __base& operator=(const __base&); -public: - _LIBCUDACXX_INLINE_VISIBILITY __base() {} - _LIBCUDACXX_INLINE_VISIBILITY virtual ~__base() {} - virtual __base* __clone() const = 0; - virtual void __clone(__base*) const = 0; - virtual void destroy() _NOEXCEPT = 0; - virtual void destroy_deallocate() _NOEXCEPT = 0; - virtual _Rp operator()(_ArgTypes&& ...) = 0; -#ifndef _LIBCUDACXX_NO_RTTI - virtual const void* target(const type_info&) const _NOEXCEPT = 0; - virtual const std::type_info& target_type() const _NOEXCEPT = 0; -#endif // _LIBCUDACXX_NO_RTTI -}; - -// __func implements __base for a given functor type. - -template class __func; - -template -class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> - : public __base<_Rp(_ArgTypes...)> -{ - __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; -public: - _LIBCUDACXX_INLINE_VISIBILITY - explicit __func(_Fp&& __f) - : __f_(_CUDA_VSTD::move(__f)) {} - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __func(const _Fp& __f, const _Alloc& __a) - : __f_(__f, __a) {} - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __func(const _Fp& __f, _Alloc&& __a) - : __f_(__f, _CUDA_VSTD::move(__a)) {} - - _LIBCUDACXX_INLINE_VISIBILITY - explicit __func(_Fp&& __f, _Alloc&& __a) - : __f_(_CUDA_VSTD::move(__f), _CUDA_VSTD::move(__a)) {} - - virtual __base<_Rp(_ArgTypes...)>* __clone() const; - virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; - virtual void destroy() _NOEXCEPT; - virtual void destroy_deallocate() _NOEXCEPT; - virtual _Rp operator()(_ArgTypes&&... __arg); -#ifndef _LIBCUDACXX_NO_RTTI - virtual const void* target(const type_info&) const _NOEXCEPT; - virtual const std::type_info& target_type() const _NOEXCEPT; -#endif // _LIBCUDACXX_NO_RTTI -}; - -template -__base<_Rp(_ArgTypes...)>* -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.__get_allocator()); - typedef __allocator_destructor<_Ap> _Dp; - unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); - ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); - return __hold.release(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const -{ - ::new (__p) __func(__f_.__target(), __f_.__get_allocator()); -} - -template -void -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT -{ - __f_.destroy(); -} - -template -void -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT -{ - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; - _Ap __a(__f_.__get_allocator()); - __f_.destroy(); - __a.deallocate(this, 1); -} - -template -_Rp -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) -{ - return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); -} - -#ifndef _LIBCUDACXX_NO_RTTI - -template -const void* -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT -{ - if (__ti == typeid(_Fp)) - return &__f_.__target(); - return (const void*)0; -} - -template -const std::type_info& -__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT -{ - return typeid(_Fp); -} - -#endif // _LIBCUDACXX_NO_RTTI - -// __value_func creates a value-type from a __func. - -template class __value_func; - -template class __value_func<_Rp(_ArgTypes...)> -{ - typename aligned_storage<3 * sizeof(void*)>::type __buf_; - - typedef __base<_Rp(_ArgTypes...)> __func; - __func* __f_; - - _LIBCUDACXX_NO_CFI static __func* __as_base(void* p) - { - return reinterpret_cast<__func*>(p); - } - - public: - _LIBCUDACXX_INLINE_VISIBILITY - __value_func() _NOEXCEPT : __f_(0) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) - : __f_(0) - { - typedef allocator_traits<_Alloc> __alloc_traits; - typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; - - if (__function::__not_null(__f)) - { - _FunAlloc __af(__a); - if (sizeof(_Fun) <= sizeof(__buf_) && - is_nothrow_copy_constructible<_Fp>::value && - is_nothrow_copy_constructible<_FunAlloc>::value) - { - __f_ = - ::new ((void*)&__buf_) _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); - } - else - { - typedef __allocator_destructor<_FunAlloc> _Dp; - unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); - ::new ((void*)__hold.get()) _Fun(_CUDA_VSTD::move(__f), _Alloc(__a)); - __f_ = __hold.release(); - } - } - } - - template , __value_func>::value>::type> - _LIBCUDACXX_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) - : __value_func(std::forward<_Fp>(__f), allocator<_Fp>()) {} - - _LIBCUDACXX_INLINE_VISIBILITY - __value_func(const __value_func& __f) - { - if (__f.__f_ == 0) - __f_ = 0; - else if ((void*)__f.__f_ == &__f.__buf_) - { - __f_ = __as_base(&__buf_); - __f.__f_->__clone(__f_); - } - else - __f_ = __f.__f_->__clone(); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __value_func(__value_func&& __f) _NOEXCEPT - { - if (__f.__f_ == 0) - __f_ = 0; - else if ((void*)__f.__f_ == &__f.__buf_) - { - __f_ = __as_base(&__buf_); - __f.__f_->__clone(__f_); - } - else - { - __f_ = __f.__f_; - __f.__f_ = 0; - } - } - - _LIBCUDACXX_INLINE_VISIBILITY - ~__value_func() - { - if ((void*)__f_ == &__buf_) - __f_->destroy(); - else if (__f_) - __f_->destroy_deallocate(); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __value_func& operator=(__value_func&& __f) - { - *this = nullptr; - if (__f.__f_ == 0) - __f_ = 0; - else if ((void*)__f.__f_ == &__f.__buf_) - { - __f_ = __as_base(&__buf_); - __f.__f_->__clone(__f_); - } - else - { - __f_ = __f.__f_; - __f.__f_ = 0; - } - return *this; - } - - _LIBCUDACXX_INLINE_VISIBILITY - __value_func& operator=(nullptr_t) - { - __func* __f = __f_; - __f_ = 0; - if ((void*)__f == &__buf_) - __f->destroy(); - else if (__f) - __f->destroy_deallocate(); - return *this; - } - - _LIBCUDACXX_INLINE_VISIBILITY - _Rp operator()(_ArgTypes&&... __args) const - { - if (__f_ == 0) - __throw_bad_function_call(); - return (*__f_)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); - } - - _LIBCUDACXX_INLINE_VISIBILITY - void swap(__value_func& __f) _NOEXCEPT - { - if (&__f == this) - return; - if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) - { - typename aligned_storage::type __tempbuf; - __func* __t = __as_base(&__tempbuf); - __f_->__clone(__t); - __f_->destroy(); - __f_ = 0; - __f.__f_->__clone(__as_base(&__buf_)); - __f.__f_->destroy(); - __f.__f_ = 0; - __f_ = __as_base(&__buf_); - __t->__clone(__as_base(&__f.__buf_)); - __t->destroy(); - __f.__f_ = __as_base(&__f.__buf_); - } - else if ((void*)__f_ == &__buf_) - { - __f_->__clone(__as_base(&__f.__buf_)); - __f_->destroy(); - __f_ = __f.__f_; - __f.__f_ = __as_base(&__f.__buf_); - } - else if ((void*)__f.__f_ == &__f.__buf_) - { - __f.__f_->__clone(__as_base(&__buf_)); - __f.__f_->destroy(); - __f.__f_ = __f_; - __f_ = __as_base(&__buf_); - } - else - _CUDA_VSTD::swap(__f_, __f.__f_); - } - - _LIBCUDACXX_INLINE_VISIBILITY - _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != 0; } - -#ifndef _LIBCUDACXX_NO_RTTI - _LIBCUDACXX_INLINE_VISIBILITY - const std::type_info& target_type() const _NOEXCEPT - { - if (__f_ == 0) - return typeid(void); - return __f_->target_type(); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT - { - if (__f_ == 0) - return 0; - return (const _Tp*)__f_->target(typeid(_Tp)); - } -#endif // _LIBCUDACXX_NO_RTTI -}; - -// Storage for a functor object, to be used with __policy to manage copy and -// destruction. -union __policy_storage -{ - mutable char __small[sizeof(void*) * 2]; - void* __large; -}; - -// True if _Fun can safely be held in __policy_storage.__small. -template -struct __use_small_storage - : public _CUDA_VSTD::integral_constant< - bool, sizeof(_Fun) <= sizeof(__policy_storage) && - _LIBCUDACXX_ALIGNOF(_Fun) <= _LIBCUDACXX_ALIGNOF(__policy_storage) && - _CUDA_VSTD::is_trivially_copy_constructible<_Fun>::value && - _CUDA_VSTD::is_trivially_destructible<_Fun>::value> {}; - -// Policy contains information about how to copy, destroy, and move the -// underlying functor. You can think of it as a vtable of sorts. -struct __policy -{ - // Used to copy or destroy __large values. null for trivial objects. - void* (*const __clone)(const void*); - void (*const __destroy)(void*); - - // True if this is the null policy (no value). - const bool __is_null; - - // The target type. May be null if RTTI is disabled. - const std::type_info* const __type_info; - - // Returns a pointer to a static policy object suitable for the functor - // type. - template - _LIBCUDACXX_INLINE_VISIBILITY static const __policy* __create() - { - return __choose_policy<_Fun>(__use_small_storage<_Fun>()); - } - - _LIBCUDACXX_INLINE_VISIBILITY - static const __policy* __create_empty() - { - static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = {nullptr, nullptr, - true, -#ifndef _LIBCUDACXX_NO_RTTI - &typeid(void) -#else - nullptr -#endif - }; - return &__policy_; - } - - private: - template static void* __large_clone(const void* __s) - { - const _Fun* __f = static_cast(__s); - return __f->__clone(); - } - - template - static void __large_destroy(void* __s) { - _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY static const __policy* - __choose_policy(/* is_small = */ false_type) { - static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { - &__large_clone<_Fun>, &__large_destroy<_Fun>, false, -#ifndef _LIBCUDACXX_NO_RTTI - &typeid(typename _Fun::_Target) -#else - nullptr -#endif - }; - return &__policy_; - } - - template - _LIBCUDACXX_INLINE_VISIBILITY static const __policy* - __choose_policy(/* is_small = */ true_type) - { - static const _LIBCUDACXX_CONSTEXPR __policy __policy_ = { - nullptr, nullptr, false, -#ifndef _LIBCUDACXX_NO_RTTI - &typeid(typename _Fun::_Target) -#else - nullptr -#endif - }; - return &__policy_; - } -}; - -// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is -// faster for types that can be passed in registers. -template -using __fast_forward = - typename _CUDA_VSTD::conditional<_CUDA_VSTD::is_scalar<_Tp>::value, _Tp, _Tp&&>::type; - -// __policy_invoker calls an instance of __alloc_func held in __policy_storage. - -template struct __policy_invoker; - -template -struct __policy_invoker<_Rp(_ArgTypes...)> -{ - typedef _Rp (*__Call)(const __policy_storage*, - __fast_forward<_ArgTypes>...); - - __Call __call_; - - // Creates an invoker that throws bad_function_call. - _LIBCUDACXX_INLINE_VISIBILITY - __policy_invoker() : __call_(&__call_empty) {} - - // Creates an invoker that calls the given instance of __func. - template - _LIBCUDACXX_INLINE_VISIBILITY static __policy_invoker __create() - { - return __policy_invoker(&__call_impl<_Fun>); - } - - private: - _LIBCUDACXX_INLINE_VISIBILITY - explicit __policy_invoker(__Call __c) : __call_(__c) {} - - static _Rp __call_empty(const __policy_storage*, - __fast_forward<_ArgTypes>...) - { - __throw_bad_function_call(); - } - - template - static _Rp __call_impl(const __policy_storage* __buf, - __fast_forward<_ArgTypes>... __args) - { - _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value - ? &__buf->__small - : __buf->__large); - return (*__f)(_CUDA_VSTD::forward<_ArgTypes>(__args)...); - } -}; - -// __policy_func uses a __policy and __policy_invoker to create a type-erased, -// copyable functor. - -template class __policy_func; - -template class __policy_func<_Rp(_ArgTypes...)> -{ - // Inline storage for small objects. - __policy_storage __buf_; - - // Calls the value stored in __buf_. This could technically be part of - // policy, but storing it here eliminates a level of indirection inside - // operator(). - typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; - __invoker __invoker_; - - // The policy that describes how to move / copy / destroy __buf_. Never - // null, even if the function is empty. - const __policy* __policy_; - - public: - _LIBCUDACXX_INLINE_VISIBILITY - __policy_func() : __policy_(__policy::__create_empty()) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) - : __policy_(__policy::__create_empty()) - { - typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; - typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; - - if (__function::__not_null(__f)) - { - __invoker_ = __invoker::template __create<_Fun>(); - __policy_ = __policy::__create<_Fun>(); - - _FunAlloc __af(__a); - if (__use_small_storage<_Fun>()) - { - ::new ((void*)&__buf_.__small) - _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); - } - else - { - typedef __allocator_destructor<_FunAlloc> _Dp; - unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); - ::new ((void*)__hold.get()) - _Fun(_CUDA_VSTD::move(__f), _Alloc(__af)); - __buf_.__large = __hold.release(); - } - } - } - - template , __policy_func>::value>::type> - _LIBCUDACXX_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) - : __policy_(__policy::__create_empty()) { - typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; - - if (__function::__not_null(__f)) { - __invoker_ = __invoker::template __create<_Fun>(); - __policy_ = __policy::__create<_Fun>(); - if (__use_small_storage<_Fun>()) { - ::new ((void*)&__buf_.__small) _Fun(_CUDA_VSTD::move(__f)); - } else { - __builtin_new_allocator::__holder_t __hold = - __builtin_new_allocator::__allocate_type<_Fun>(1); - __buf_.__large = ::new (__hold.get()) _Fun(_CUDA_VSTD::move(__f)); - (void)__hold.release(); - } - } - } - - _LIBCUDACXX_INLINE_VISIBILITY - __policy_func(const __policy_func& __f) - : __buf_(__f.__buf_), __invoker_(__f.__invoker_), - __policy_(__f.__policy_) - { - if (__policy_->__clone) - __buf_.__large = __policy_->__clone(__f.__buf_.__large); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __policy_func(__policy_func&& __f) - : __buf_(__f.__buf_), __invoker_(__f.__invoker_), - __policy_(__f.__policy_) - { - if (__policy_->__destroy) - { - __f.__policy_ = __policy::__create_empty(); - __f.__invoker_ = __invoker(); - } - } - - _LIBCUDACXX_INLINE_VISIBILITY - ~__policy_func() - { - if (__policy_->__destroy) - __policy_->__destroy(__buf_.__large); - } - - _LIBCUDACXX_INLINE_VISIBILITY - __policy_func& operator=(__policy_func&& __f) - { - *this = nullptr; - __buf_ = __f.__buf_; - __invoker_ = __f.__invoker_; - __policy_ = __f.__policy_; - __f.__policy_ = __policy::__create_empty(); - __f.__invoker_ = __invoker(); - return *this; - } - - _LIBCUDACXX_INLINE_VISIBILITY - __policy_func& operator=(nullptr_t) - { - const __policy* __p = __policy_; - __policy_ = __policy::__create_empty(); - __invoker_ = __invoker(); - if (__p->__destroy) - __p->__destroy(__buf_.__large); - return *this; - } - - _LIBCUDACXX_INLINE_VISIBILITY - _Rp operator()(_ArgTypes&&... __args) const - { - return __invoker_.__call_(_CUDA_VSTD::addressof(__buf_), - _CUDA_VSTD::forward<_ArgTypes>(__args)...); - } - - _LIBCUDACXX_INLINE_VISIBILITY - void swap(__policy_func& __f) - { - _CUDA_VSTD::swap(__invoker_, __f.__invoker_); - _CUDA_VSTD::swap(__policy_, __f.__policy_); - _CUDA_VSTD::swap(__buf_, __f.__buf_); - } - - _LIBCUDACXX_INLINE_VISIBILITY - explicit operator bool() const _NOEXCEPT - { - return !__policy_->__is_null; - } - -#ifndef _LIBCUDACXX_NO_RTTI - _LIBCUDACXX_INLINE_VISIBILITY - const std::type_info& target_type() const _NOEXCEPT - { - return *__policy_->__type_info; - } - - template - _LIBCUDACXX_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT - { - if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) - return nullptr; - if (__policy_->__clone) // Out of line storage. - return reinterpret_cast(__buf_.__large); - else - return reinterpret_cast(&__buf_.__small); - } -#endif // _LIBCUDACXX_NO_RTTI -}; - -} // __function - -template -class _LIBCUDACXX_TEMPLATE_VIS function<_Rp(_ArgTypes...)> - : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, - public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> -{ -#ifndef _LIBCUDACXX_ABI_OPTIMIZED_FUNCTION - typedef __function::__value_func<_Rp(_ArgTypes...)> __func; -#else - typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; -#endif - - __func __f_; - - template , function>, - __invokable<_Fp&, _ArgTypes...> - >::value> - struct __callable; - template - struct __callable<_Fp, true> - { - static const bool value = is_same::value || - is_convertible::type, - _Rp>::value; - }; - template - struct __callable<_Fp, false> - { - static const bool value = false; - }; - - template - using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type; -public: - typedef _Rp result_type; - - // construct/copy/destroy: - _LIBCUDACXX_INLINE_VISIBILITY - function() _NOEXCEPT { } - _LIBCUDACXX_INLINE_VISIBILITY - function(nullptr_t) _NOEXCEPT {} - function(const function&); - function(function&&) _NOEXCEPT; - template> - function(_Fp); - -#if _LIBCUDACXX_STD_VER <= 14 - template - _LIBCUDACXX_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} - template - _LIBCUDACXX_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} - template - function(allocator_arg_t, const _Alloc&, const function&); - template - function(allocator_arg_t, const _Alloc&, function&&); - template> - function(allocator_arg_t, const _Alloc& __a, _Fp __f); -#endif - - function& operator=(const function&); - function& operator=(function&&) _NOEXCEPT; - function& operator=(nullptr_t) _NOEXCEPT; - template> - function& operator=(_Fp&&); - - ~function(); - - // function modifiers: - void swap(function&) _NOEXCEPT; - -#if _LIBCUDACXX_STD_VER <= 14 - template - _LIBCUDACXX_INLINE_VISIBILITY - void assign(_Fp&& __f, const _Alloc& __a) - {function(allocator_arg, __a, _CUDA_VSTD::forward<_Fp>(__f)).swap(*this);} -#endif - - // function capacity: - _LIBCUDACXX_INLINE_VISIBILITY - _LIBCUDACXX_EXPLICIT operator bool() const _NOEXCEPT { - return static_cast(__f_); - } - - // deleted overloads close possible hole in the type system - template - bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; - template - bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; -public: - // function invocation: - _Rp operator()(_ArgTypes...) const; - -#ifndef _LIBCUDACXX_NO_RTTI - // function target access: - const std::type_info& target_type() const _NOEXCEPT; - template _Tp* target() _NOEXCEPT; - template const _Tp* target() const _NOEXCEPT; -#endif // _LIBCUDACXX_NO_RTTI -}; - -#ifndef _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES -template -function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; - -template -struct __strip_signature; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; - -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; -template -struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; - -template::type> -function(_Fp) -> function<_Stripped>; -#endif // !_LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES - -template -function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} - -#if _LIBCUDACXX_STD_VER <= 14 -template -template -function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, - const function& __f) : __f_(__f.__f_) {} -#endif - -template -function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT - : __f_(_CUDA_VSTD::move(__f.__f_)) {} - -#if _LIBCUDACXX_STD_VER <= 14 -template -template -function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, - function&& __f) - : __f_(_CUDA_VSTD::move(__f.__f_)) {} -#endif - -template -template -function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_CUDA_VSTD::move(__f)) {} - -#if _LIBCUDACXX_STD_VER <= 14 -template -template -function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, - _Fp __f) - : __f_(_CUDA_VSTD::move(__f), __a) {} -#endif - -template -function<_Rp(_ArgTypes...)>& -function<_Rp(_ArgTypes...)>::operator=(const function& __f) -{ - function(__f).swap(*this); - return *this; -} - -template -function<_Rp(_ArgTypes...)>& -function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT -{ - __f_ = std::move(__f.__f_); - return *this; -} - -template -function<_Rp(_ArgTypes...)>& -function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT -{ - __f_ = nullptr; - return *this; -} - -template -template -function<_Rp(_ArgTypes...)>& -function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) -{ - function(_CUDA_VSTD::forward<_Fp>(__f)).swap(*this); - return *this; -} - -template -function<_Rp(_ArgTypes...)>::~function() {} - -template -void -function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT -{ - __f_.swap(__f.__f_); -} - -template -_Rp -function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const -{ - return __f_(_CUDA_VSTD::forward<_ArgTypes>(__arg)...); -} - -#ifndef _LIBCUDACXX_NO_RTTI - -template -const std::type_info& -function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT -{ - return __f_.target_type(); -} - -template -template -_Tp* -function<_Rp(_ArgTypes...)>::target() _NOEXCEPT -{ - return (_Tp*)(__f_.template target<_Tp>()); -} - -template -template -const _Tp* -function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT -{ - return __f_.template target<_Tp>(); -} - -#endif // _LIBCUDACXX_NO_RTTI - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -bool -operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -bool -operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -bool -operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -bool -operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -void -swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT -{return __x.swap(__y);} - -#else // _LIBCUDACXX_CXX03_LANG - -#include <__functional_03> - -#endif - -#endif // __cuda_std__ - -//////////////////////////////////////////////////////////////////////////////// -// BIND -//============================================================================== - -// `cuda::std::bind` is not currently supported. - -#ifndef __cuda_std__ - -template struct __is_bind_expression : public false_type {}; -template struct _LIBCUDACXX_TEMPLATE_VIS is_bind_expression - : public __is_bind_expression<__remove_cv_t<_Tp>> {}; - -#if _LIBCUDACXX_STD_VER > 14 -template -_LIBCUDACXX_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; -#endif - -template struct __is_placeholder : public integral_constant {}; -template struct _LIBCUDACXX_TEMPLATE_VIS is_placeholder - : public __is_placeholder<__remove_cv_t<_Tp>> {}; - -#if _LIBCUDACXX_STD_VER > 14 -template -_LIBCUDACXX_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; -#endif - -namespace placeholders -{ - -template struct __ph {}; - -#if defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) -_LIBCUDACXX_FUNC_VIS extern const __ph<1> _1; -_LIBCUDACXX_FUNC_VIS extern const __ph<2> _2; -_LIBCUDACXX_FUNC_VIS extern const __ph<3> _3; -_LIBCUDACXX_FUNC_VIS extern const __ph<4> _4; -_LIBCUDACXX_FUNC_VIS extern const __ph<5> _5; -_LIBCUDACXX_FUNC_VIS extern const __ph<6> _6; -_LIBCUDACXX_FUNC_VIS extern const __ph<7> _7; -_LIBCUDACXX_FUNC_VIS extern const __ph<8> _8; -_LIBCUDACXX_FUNC_VIS extern const __ph<9> _9; -_LIBCUDACXX_FUNC_VIS extern const __ph<10> _10; -#else -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<1> _1{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<2> _2{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<3> _3{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<4> _4{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<5> _5{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<6> _6{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<7> _7{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<8> _8{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<9> _9{}; -/* _LIBCUDACXX_INLINE_VAR */ constexpr __ph<10> _10{}; -#endif // defined(_LIBCUDACXX_CXX03_LANG) || defined(_LIBCUDACXX_BUILDING_LIBRARY) - -} // placeholders - -template -struct __is_placeholder > - : public integral_constant {}; - - -#ifndef _LIBCUDACXX_CXX03_LANG - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -_Tp& -__mu(reference_wrapper<_Tp> __t, _Uj&) -{ - return __t.get(); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename __invoke_of<_Ti&, _Uj...>::type -__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) -{ - return __ti(_CUDA_VSTD::forward<_Uj>(_CUDA_VSTD::get<_Indx>(__uj))...); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename _EnableIf -< - is_bind_expression<_Ti>::value, - __invoke_of<_Ti&, _Uj...> ->::type -__mu(_Ti& __ti, tuple<_Uj...>& __uj) -{ - typedef typename __make_tuple_indices::type __indices; - return __mu_expand(__ti, __uj, __indices()); -} - -template -struct __mu_return2 {}; - -template -struct __mu_return2 -{ - typedef typename tuple_element::value - 1, _Uj>::type type; -}; - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename enable_if -< - 0 < is_placeholder<_Ti>::value, - typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type ->::type -__mu(_Ti&, _Uj& __uj) -{ - const size_t _Indx = is_placeholder<_Ti>::value - 1; - return _CUDA_VSTD::forward::type>(_CUDA_VSTD::get<_Indx>(__uj)); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename enable_if -< - !is_bind_expression<_Ti>::value && - is_placeholder<_Ti>::value == 0 && - !__is_reference_wrapper<_Ti>::value, - _Ti& ->::type -__mu(_Ti& __ti, _Uj&) -{ - return __ti; -} - -template -struct __mu_return_impl; - -template -struct __mu_return_invokable // false -{ - typedef __nat type; -}; - -template -struct __mu_return_invokable -{ - typedef typename __invoke_of<_Ti&, _Uj...>::type type; -}; - -template -struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > - : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> -{ -}; - -template -struct __mu_return_impl<_Ti, false, false, true, _TupleUj> -{ - typedef typename tuple_element::value - 1, - _TupleUj>::type&& type; -}; - -template -struct __mu_return_impl<_Ti, true, false, false, _TupleUj> -{ - typedef typename _Ti::type& type; -}; - -template -struct __mu_return_impl<_Ti, false, false, false, _TupleUj> -{ - typedef _Ti& type; -}; - -template -struct __mu_return - : public __mu_return_impl<_Ti, - __is_reference_wrapper<_Ti>::value, - is_bind_expression<_Ti>::value, - 0 < is_placeholder<_Ti>::value && - is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, - _TupleUj> -{ -}; - -template -struct __is_valid_bind_return -{ - static const bool value = false; -}; - -template -struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> -{ - static const bool value = __invokable<_Fp, - typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; -}; - -template -struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> -{ - static const bool value = __invokable<_Fp, - typename __mu_return::type...>::value; -}; - -template ::value> -struct __bind_return; - -template -struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> -{ - typedef typename __invoke_of - < - _Fp&, - typename __mu_return - < - _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template -struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> -{ - typedef typename __invoke_of - < - _Fp&, - typename __mu_return - < - const _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -typename __bind_return<_Fp, _BoundArgs, _Args>::type -__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, - _Args&& __args) -{ - return _CUDA_VSTD::__invoke(__f, _CUDA_VSTD::__mu(_CUDA_VSTD::get<_Indx>(__bound_args), __args)...); -} - -template -class __bind - : public __weak_result_type<__decay_t<_Fp>> -{ -protected: - typedef __decay_t<_Fp> _Fd; - typedef tuple<__decay_t<_BoundArgs>...> _Td; -private: - _Fd __f_; - _Td __bound_args_; - - typedef typename __make_tuple_indices::type __indices; -public: - template ::value && - !is_same<__libcpp_remove_reference_t<_Gp>, - __bind>::value - >::type> - _LIBCUDACXX_INLINE_VISIBILITY - explicit __bind(_Gp&& __f, _BA&& ...__bound_args) - : __f_(_CUDA_VSTD::forward<_Gp>(__f)), - __bound_args_(_CUDA_VSTD::forward<_BA>(__bound_args)...) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type - operator()(_Args&& ...__args) - { - return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename __bind_return >::type - operator()(_Args&& ...__args) const - { - return _CUDA_VSTD::__apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(_CUDA_VSTD::forward<_Args>(__args)...)); - } -}; - -template -struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; - -template -class __bind_r - : public __bind<_Fp, _BoundArgs...> -{ - typedef __bind<_Fp, _BoundArgs...> base; - typedef typename base::_Fd _Fd; - typedef typename base::_Td _Td; -public: - typedef _Rp result_type; - - - template ::value && - !is_same<__libcpp_remove_reference_t<_Gp>, - __bind_r>::value - >::type> - _LIBCUDACXX_INLINE_VISIBILITY - explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) - : base(_CUDA_VSTD::forward<_Gp>(__f), - _CUDA_VSTD::forward<_BA>(__bound_args)...) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename enable_if - < - is_convertible >::type, - result_type>::value || is_void<_Rp>::value, - result_type - >::type - operator()(_Args&& ...__args) - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); - } - - template - _LIBCUDACXX_INLINE_VISIBILITY - typename enable_if - < - is_convertible >::type, - result_type>::value || is_void<_Rp>::value, - result_type - >::type - operator()(_Args&& ...__args) const - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast(*this), _CUDA_VSTD::forward<_Args>(__args)...); - } -}; - -template -struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -__bind<_Fp, _BoundArgs...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind<_Fp, _BoundArgs...> type; - return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); -} - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -__bind_r<_Rp, _Fp, _BoundArgs...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; - return type(_CUDA_VSTD::forward<_Fp>(__f), _CUDA_VSTD::forward<_BoundArgs>(__bound_args)...); -} - -#endif // _LIBCUDACXX_CXX03_LANG - -#endif // __cuda_std__ - -#if _LIBCUDACXX_STD_VER > 14 - -template -class _LIBCUDACXX_TEMPLATE_VIS __not_fn_imp { - _DecayFunc __fd; - -public: - __not_fn_imp() = delete; - - template - _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Args&& ...__args) & - noexcept(noexcept(!_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...))) - -> decltype( !_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...)) - { return !_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...); } - - template - _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Args&& ...__args) && - noexcept(noexcept(!_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...))) - -> decltype( !_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...)) - { return !_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...); } - - template - _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Args&& ...__args) const& - noexcept(noexcept(!_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...))) - -> decltype( !_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...)) - { return !_CUDA_VSTD::invoke(__fd, _CUDA_VSTD::forward<_Args>(__args)...); } - - - template - _LIBCUDACXX_INLINE_VISIBILITY - auto operator()(_Args&& ...__args) const&& - noexcept(noexcept(!_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...))) - -> decltype( !_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...)) - { return !_CUDA_VSTD::invoke(_CUDA_VSTD::move(__fd), _CUDA_VSTD::forward<_Args>(__args)...); } - -private: - template , __not_fn_imp>::value>> - _LIBCUDACXX_INLINE_VISIBILITY - explicit __not_fn_imp(_RawFunc&& __rf) - : __fd(_CUDA_VSTD::forward<_RawFunc>(__rf)) {} - - template - friend inline _LIBCUDACXX_INLINE_VISIBILITY - __not_fn_imp> not_fn(_RawFunc&&); -}; - -template -inline _LIBCUDACXX_INLINE_VISIBILITY -__not_fn_imp> not_fn(_RawFunc&& __fn) { - return __not_fn_imp>(_CUDA_VSTD::forward<_RawFunc>(__fn)); -} - -#endif - -// struct hash in - -// Searchers are not currently supported. - - -template -_LIBCUDACXX_EXECUTION_SPACE_SPECIFIER _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 -pair<_ForwardIterator1, _ForwardIterator1> -__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, - forward_iterator_tag, forward_iterator_tag) -{ - if (__first2 == __last2) - return make_pair(__first1, __first1); // Everything matches an empty sequence - while (true) - { - // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks - while (true) - { - if (__first1 == __last1) // return __last1 if no element matches *__first2 - return make_pair(__last1, __last1); - if (__pred(*__first1, *__first2)) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _ForwardIterator1 __m1 = __first1; - _ForwardIterator2 __m2 = __first2; - while (true) - { - if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) - return make_pair(__first1, __m1); - if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found - return make_pair(__last1, __last1); - if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 - { - ++__first1; - break; - } // else there is a match, check next elements - } - } -} - -template -_LIBCUDACXX_EXECUTION_SPACE_SPECIFIER _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 -pair<_RandomAccessIterator1, _RandomAccessIterator1> -__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, - _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, - random_access_iterator_tag, random_access_iterator_tag) -{ - typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; - typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; - // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - const _D2 __len2 = __last2 - __first2; - if (__len2 == 0) - return make_pair(__first1, __first1); - const _D1 __len1 = __last1 - __first1; - if (__len1 < __len2) - return make_pair(__last1, __last1); - const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here - - while (true) - { - while (true) - { - if (__first1 == __s) - return make_pair(__last1, __last1); - if (__pred(*__first1, *__first2)) - break; - ++__first1; - } - - _RandomAccessIterator1 __m1 = __first1; - _RandomAccessIterator2 __m2 = __first2; - while (true) - { - if (++__m2 == __last2) - return make_pair(__first1, __first1 + __len2); - ++__m1; // no need to check range on __m1 because __s guarantees we have enough source - if (!__pred(*__m1, *__m2)) - { - ++__first1; - break; - } - } - } -} - -#ifndef __cuda_std__ -#if _LIBCUDACXX_STD_VER > 14 - -// default searcher -template> -class _LIBCUDACXX_TYPE_VIS default_searcher { -public: - _LIBCUDACXX_INLINE_VISIBILITY - default_searcher(_ForwardIterator __f, _ForwardIterator __l, - _BinaryPredicate __p = _BinaryPredicate()) - : __first_(__f), __last_(__l), __pred_(__p) {} - - template - _LIBCUDACXX_INLINE_VISIBILITY - pair<_ForwardIterator2, _ForwardIterator2> - operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const - { - return _CUDA_VSTD::__search(__f, __l, __first_, __last_, __pred_, - typename _CUDA_VSTD::iterator_traits<_ForwardIterator>::iterator_category(), - typename _CUDA_VSTD::iterator_traits<_ForwardIterator2>::iterator_category()); - } - -private: - _ForwardIterator __first_; - _ForwardIterator __last_; - _BinaryPredicate __pred_; - }; - -#endif // _LIBCUDACXX_STD_VER > 14 - -#endif // __cuda_std__ - -_LIBCUDACXX_END_NAMESPACE_STD - -#ifndef __cuda_std__ -#include <__pragma_pop> -#endif //__cuda_std__ - #endif // _LIBCUDACXX_FUNCTIONAL diff --git a/include/cuda/std/detail/libcxx/include/future b/include/cuda/std/detail/libcxx/include/future index ad8617b4e4..35c0b3abd0 100644 --- a/include/cuda/std/detail/libcxx/include/future +++ b/include/cuda/std/detail/libcxx/include/future @@ -1425,9 +1425,9 @@ promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_state_alloc<_Rp, _Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a(__a0); - unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + unique_ptr<_State, _Dest2> __hold(__a.allocate(1), _Dest2(__a, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _CUDA_VSTD::addressof(*__hold.release()); } @@ -1587,9 +1587,9 @@ promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_state_alloc<_Rp&, _Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a(__a0); - unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + unique_ptr<_State, _Dest2> __hold(__a.allocate(1), _Dest2(__a, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _CUDA_VSTD::addressof(*__hold.release()); } @@ -1717,9 +1717,9 @@ promise::promise(allocator_arg_t, const _Alloc& __a0) { typedef __assoc_sub_state_alloc<_Alloc> _State; typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a(__a0); - unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1)); + unique_ptr<_State, _Dest2> __hold(__a.allocate(1), _Dest2(__a, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold.get()))) _State(__a0); __state_ = _CUDA_VSTD::addressof(*__hold.release()); } diff --git a/include/cuda/std/detail/libcxx/include/memory b/include/cuda/std/detail/libcxx/include/memory index 225774e889..f961ab74c1 100644 --- a/include/cuda/std/detail/libcxx/include/memory +++ b/include/cuda/std/detail/libcxx/include/memory @@ -1198,7 +1198,7 @@ struct __has_construct : std::false_type {}; template struct __has_construct<_Alloc, _Pointer, _Tp, __void_t< - decltype(_CUDA_VSTD::declval<_Alloc>().construct(_CUDA_VSTD::declval<_Pointer>(), _CUDA_VSTD::declval<_Tp>()))>> + decltype(_CUDA_VSTD::declval<_Alloc>().construct(_CUDA_VSTD::declval<_Pointer>(), _CUDA_VSTD::declval<_Tp>()))>> : std::true_type {}; template @@ -1206,7 +1206,7 @@ struct __has_destroy : false_type {}; template struct __has_destroy<_Alloc, _Pointer, __void_t< - decltype(_CUDA_VSTD::declval<_Alloc>().destroy(_CUDA_VSTD::declval<_Pointer>()))>> + decltype(_CUDA_VSTD::declval<_Alloc>().destroy(_CUDA_VSTD::declval<_Pointer>()))>> : std::true_type {}; template @@ -2616,136 +2616,136 @@ typename enable_if< >::type swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} +operator==(const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) {return __x.get() == __y.get();} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} +operator!=(const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) {return !(__x == __y);} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) +operator< (const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) { - typedef typename unique_ptr<_T1, _D1>::pointer _P1; - typedef typename unique_ptr<_T2, _D2>::pointer _P2; + typedef typename unique_ptr<_T1, _Dest1>::pointer _P1; + typedef typename unique_ptr<_T2, _Dest2>::pointer _P2; typedef typename common_type<_P1, _P2>::type _Vp; return less<_Vp>()(__x.get(), __y.get()); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} +operator> (const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) {return __y < __x;} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} +operator<=(const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) {return !(__y < __x);} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} +operator>=(const unique_ptr<_T1, _Dest1>& __x, const unique_ptr<_T2, _Dest2>& __y) {return !(__x < __y);} -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT +operator==(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) _NOEXCEPT { return !__x; } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT +operator==(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) _NOEXCEPT { return !__x; } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT +operator!=(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) _NOEXCEPT { return static_cast(__x); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT +operator!=(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) _NOEXCEPT { return static_cast(__x); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) +operator<(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) { - typedef typename unique_ptr<_T1, _D1>::pointer _P1; + typedef typename unique_ptr<_T1, _Dest1>::pointer _P1; return less<_P1>()(__x.get(), nullptr); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) +operator<(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) { - typedef typename unique_ptr<_T1, _D1>::pointer _P1; + typedef typename unique_ptr<_T1, _Dest1>::pointer _P1; return less<_P1>()(nullptr, __x.get()); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) +operator>(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) { return nullptr < __x; } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) +operator>(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) { return __x < nullptr; } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +operator<=(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) { return !(nullptr < __x); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +operator<=(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) { return !(__x < nullptr); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) +operator>=(const unique_ptr<_T1, _Dest1>& __x, nullptr_t) { return !(__x < nullptr); } -template +template inline _LIBCUDACXX_INLINE_VISIBILITY bool -operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) +operator>=(nullptr_t, const unique_ptr<_T1, _Dest1>& __x) { return !(nullptr < __x); } @@ -3743,9 +3743,9 @@ shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, #endif // _LIBCUDACXX_NO_EXCEPTIONS typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + unique_ptr<_CntrlBlk, _Dest2> __hold2(__a2.allocate(1), _Dest2(__a2, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold2.get()))) _CntrlBlk(__p, __d, __a); __cntrl_ = _CUDA_VSTD::addressof(*__hold2.release()); @@ -3771,9 +3771,9 @@ shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a) #endif // _LIBCUDACXX_NO_EXCEPTIONS typedef __shared_ptr_pointer _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + unique_ptr<_CntrlBlk, _Dest2> __hold2(__a2.allocate(1), _Dest2(__a2, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold2.get()))) _CntrlBlk(__p, __d, __a); __cntrl_ = _CUDA_VSTD::addressof(*__hold2.release()); @@ -3936,9 +3936,9 @@ shared_ptr<_Tp>::make_shared(_Args&& ...__args) static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared" ); typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk; typedef allocator<_CntrlBlk> _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a2; - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + unique_ptr<_CntrlBlk, _Dest2> __hold2(__a2.allocate(1), _Dest2(__a2, 1)); ::new(__hold2.get()) _CntrlBlk(__a2, _CUDA_VSTD::forward<_Args>(__args)...); shared_ptr<_Tp> __r; __r.__ptr_ = __hold2.get()->get(); @@ -3955,9 +3955,9 @@ shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args) static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" ); typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk; typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2; - typedef __allocator_destructor<_A2> _D2; + typedef __allocator_destructor<_A2> _Dest2; _A2 __a2(__a); - unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1)); + unique_ptr<_CntrlBlk, _Dest2> __hold2(__a2.allocate(1), _Dest2(__a2, 1)); ::new(static_cast(_CUDA_VSTD::addressof(*__hold2.get()))) _CntrlBlk(__a, _CUDA_VSTD::forward<_Args>(__args)...); shared_ptr<_Tp> __r; diff --git a/include/cuda/std/detail/libcxx/include/version b/include/cuda/std/detail/libcxx/include/version index ea6f9a2cec..7e6e0b0819 100644 --- a/include/cuda/std/detail/libcxx/include/version +++ b/include/cuda/std/detail/libcxx/include/version @@ -246,6 +246,7 @@ __cpp_lib_void_t 201411L # if !defined(_LIBCUDACXX_HAS_NO_THREADS) # define __cpp_lib_atomic_is_always_lock_free 201603L # endif +# define __cpp_lib_bind_front 201907L # define __cpp_lib_bool_constant 201505L // # define __cpp_lib_boyer_moore_searcher 201603L # define __cpp_lib_byte 201603L @@ -315,7 +316,6 @@ __cpp_lib_void_t 201411L # if !defined(_LIBCUDACXX_HAS_NO_THREADS) && !defined(_LIBCUDACXX_AVAILABILITY_DISABLE_FTM___cpp_lib_barrier) // # define __cpp_lib_barrier 201907L # endif -// # define __cpp_lib_bind_front 201907L // # define __cpp_lib_bit_cast 201806L // # define __cpp_lib_bitops 201907L // # define __cpp_lib_bounded_array_traits 201902L diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst index 97989482af..bc941c3db8 100644 --- a/libcxx/docs/FeatureTestMacroTable.rst +++ b/libcxx/docs/FeatureTestMacroTable.rst @@ -84,6 +84,8 @@ Status ------------------------------------------------- ----------------- ``__cpp_lib_atomic_is_always_lock_free`` ``201603L`` ------------------------------------------------- ----------------- + ``__cpp_lib_bind_front`` ``201907L`` + ------------------------------------------------- ----------------- ``__cpp_lib_bool_constant`` ``201505L`` ------------------------------------------------- ----------------- ``__cpp_lib_boyer_moore_searcher`` *unimplemented* @@ -190,8 +192,6 @@ Status ------------------------------------------------- ----------------- ``__cpp_lib_barrier`` ``201907L`` ------------------------------------------------- ----------------- - ``__cpp_lib_bind_front`` *unimplemented* - ------------------------------------------------- ----------------- ``__cpp_lib_bit_cast`` *unimplemented* ------------------------------------------------- ----------------- ``__cpp_lib_bitops`` *unimplemented*