Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Modularize <utility> #350

Merged
merged 33 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f846ef
Add `auto_cast` helper macro
miscco Feb 9, 2023
94e0acb
Move `exchange` into its own file
miscco Feb 9, 2023
dc44f0d
Add tests for `declval`
miscco Feb 9, 2023
d59ef05
Add tests for `forward`
miscco Feb 9, 2023
70e0682
Add tests for `move`
miscco Feb 9, 2023
8e7570b
Move `in_place` into its own file
miscco Feb 9, 2023
0760c42
Move `piecewise_construct` into its own file
miscco Feb 9, 2023
175b28d
Add `priority_tag` helper class
miscco Feb 9, 2023
3a4afa1
Move `rel_ops` into their own file
miscco Feb 9, 2023
089e3a6
Add C++23 `to_underlying` to its own file
miscco Feb 9, 2023
5e70580
Implement C++23 `unreachable`
miscco Feb 9, 2023
b74eabc
Implement C++23 `forward_like`
miscco Feb 9, 2023
b2770e2
Implement C++20 integer comparison functions
miscco Feb 9, 2023
ff767f9
Move `integer_sequence` into its own file
miscco Feb 9, 2023
a0cdd70
Add tests for `reference_wrapper`
miscco Feb 9, 2023
4c355fc
Move `unwrap_reference` into its own file
miscco Feb 9, 2023
cc730e7
Add `array` forward declaration header
miscco Feb 9, 2023
bff2461
Add `tuple` forward declaration header
miscco Feb 9, 2023
90c9dcf
Move `__tuple_types` into its own file
miscco Feb 9, 2023
2c55bd5
Move `tuple_size` into its own file
miscco Feb 9, 2023
3d7d34e
Move `__tuple_indices` into its own file
miscco Feb 9, 2023
2bc4cf3
Move `tuple_element` to its own file
miscco Feb 9, 2023
cb34dde
Move `__tuple_like` into its own file
miscco Feb 9, 2023
e1b6217
Move `get` forward declarations into their own file
miscco Feb 9, 2023
845b171
Move `__apply_cv` into its own file
miscco Feb 9, 2023
c28a6f6
Move `__make_tuple_types` into its own file
miscco Feb 9, 2023
a3a27dd
Move sfinae_helpers into their own file
miscco Feb 9, 2023
b32a915
Move structured_bindings workaround into its own file
miscco Feb 9, 2023
7e03cd6
Replace `__tuple` with internal header files
miscco Feb 9, 2023
6380e58
Rename `__tuple_` folder to `__tuple`
miscco Feb 9, 2023
3334aaf
Move `pair` into its own file
miscco Feb 9, 2023
822c150
Move `hash` into its own file
miscco Feb 9, 2023
cd13c4b
Cleanup remaining utility header
miscco Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// REQUIRES: c++03 || c++11 || c++14 || c++17

// ADDITIONAL_COMPILE_FLAGS: -D_LIBCUDACXX_DISABLE_DEPRECATION_WARNINGS

// <functional>

// reference_wrapper

// check that binder typedefs exit

// #include <cuda/std/functional>
#include <cuda/std/utility>
#include <cuda/std/type_traits>

struct UnaryFunction
{
typedef long argument_type;
typedef char result_type;
};

struct BinaryFunction
{
typedef int first_argument_type;
typedef char second_argument_type;
typedef long result_type;
};

static_assert(cuda::std::is_same<cuda::std::reference_wrapper<int(UnaryFunction::*)()>::result_type, int>::value, "");
static_assert(cuda::std::is_same<cuda::std::reference_wrapper<int(UnaryFunction::*)()>::argument_type, UnaryFunction*>::value, "");

static_assert(cuda::std::is_same<cuda::std::reference_wrapper<int(BinaryFunction::*)(char)>::result_type, int>::value, "");
static_assert(cuda::std::is_same<cuda::std::reference_wrapper<int(BinaryFunction::*)(char)>::first_argument_type, BinaryFunction*>::value, "");
static_assert(cuda::std::is_same<cuda::std::reference_wrapper<int(BinaryFunction::*)(char)>::second_argument_type, char>::value, "");

static_assert(cuda::std::is_same<cuda::std::reference_wrapper<void(*)()>::result_type, void>::value, "");

int main(int, char**)
{
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// <functional>

// reference_wrapper

// operator T& () const;

// #include <cuda/std/functional>
#include <cuda/std/utility>
#include <cuda/std/cassert>

#include "test_macros.h"

class functor1
{
};

template <class T>
__host__ __device__ void
test(T& t)
{
cuda::std::reference_wrapper<T> r(t);
T& r2 = r;
assert(&r2 == &t);
}

__host__ __device__ void f() {}

int main(int, char**)
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// <functional>

// reference_wrapper

// reference_wrapper& operator=(const reference_wrapper<T>& x);

// #include <cuda/std/functional>
#include <cuda/std/utility>
#include <cuda/std/cassert>

#include "test_macros.h"

class functor1
{
};

struct convertible_to_int_ref {
int val = 0;
__host__ __device__ operator int&() { return val; }
__host__ __device__ operator int const&() const { return val; }
};

template <class T>
__host__ __device__ void
test(T& t)
{
cuda::std::reference_wrapper<T> r(t);
T t2 = t;
cuda::std::reference_wrapper<T> r2(t2);
r2 = r;
assert(&r2.get() == &t);
}

__host__ __device__ void f() {}
__host__ __device__ void g() {}

__host__ __device__ void
test_function()
{
cuda::std::reference_wrapper<void ()> r(f);
cuda::std::reference_wrapper<void ()> r2(g);
r2 = r;
assert(&r2.get() == &f);
}

int main(int, char**)
{
void (*fp)() = f;
test(fp);
test_function();
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);

#if TEST_STD_VER >= 11
convertible_to_int_ref convi{};
test(convi);
convertible_to_int_ref const convic{};
test(convic);

{
using Ref = cuda::std::reference_wrapper<int>;
static_assert((cuda::std::is_assignable<Ref&, int&>::value), "");
static_assert((!cuda::std::is_assignable<Ref&, int>::value), "");
static_assert((!cuda::std::is_assignable<Ref&, int&&>::value), "");
}
#endif

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//

// <functional>

// reference_wrapper

// reference_wrapper(const reference_wrapper<T>& x);

// #include <cuda/std/functional>
#include <cuda/std/utility>
#include <cuda/std/cassert>

#include "test_macros.h"

class functor1
{
};

template <class T>
__host__ __device__ void
test(T& t)
{
cuda::std::reference_wrapper<T> r(t);
cuda::std::reference_wrapper<T> r2 = r;
assert(&r2.get() == &t);
}

__host__ __device__ void f() {}

int main(int, char**)
{
void (*fp)() = f;
test(fp);
test(f);
functor1 f1;
test(f1);
int i = 0;
test(i);
const int j = 0;
test(j);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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, c++17

// <functional>
//
// reference_wrapper<T>
//
// where T is an incomplete type (since C++20)


// #include <cuda/std/functional>
#include <cuda/std/utility>
#include <cuda/std/cassert>

#include "test_macros.h"


struct Foo;

__host__ __device__ Foo& get_foo();

__host__ __device__ void test() {
Foo& foo = get_foo();
cuda::std::reference_wrapper<Foo> ref{foo};
assert(&ref.get() == &foo);
}

struct Foo { };

__host__ __device__ Foo& get_foo() {
static Foo foo;
return foo;
}

int main(int, char**) {
test();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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: gcc-7

// <functional>

// template <class T>
// reference_wrapper(T&) -> reference_wrapper<T>;

// #include <cuda/std/functional>
#include <cuda/std/utility>

#pragma nv_diag_suppress set_but_not_used

int main(int, char**) {
int i = 0;
cuda::std::reference_wrapper ri(i);
static_assert(cuda::std::is_same_v<decltype(ri), cuda::std::reference_wrapper<int>>);
cuda::std::reference_wrapper ri2(ri);
static_assert(cuda::std::is_same_v<decltype(ri2), cuda::std::reference_wrapper<int>>);
const int j = 0;
cuda::std::reference_wrapper rj(j);
static_assert(cuda::std::is_same_v<decltype(rj), cuda::std::reference_wrapper<const int>>);
cuda::std::reference_wrapper rj2(rj);
static_assert(cuda::std::is_same_v<decltype(rj2), cuda::std::reference_wrapper<const int>>);

return 0;
}
Loading