Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the sortable concept #471

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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,55 @@
//===----------------------------------------------------------------------===//
//
// 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) 2023 NVIDIA CORPORATION & AFFILIATES
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14

// template<class I, class R = ranges::less, class P = identity>
// concept sortable = see below; // since C++20

#include <cuda/std/iterator>

#include <cuda/std/functional>

using CompInt = bool(*)(int, int);
using CompDefault = cuda::std::ranges::less;

using AllConstraintsSatisfied = int*;
static_assert( cuda::std::permutable<AllConstraintsSatisfied>);
static_assert( cuda::std::indirect_strict_weak_order<CompDefault, AllConstraintsSatisfied>);
static_assert( cuda::std::sortable<AllConstraintsSatisfied>);
static_assert( cuda::std::indirect_strict_weak_order<CompInt, AllConstraintsSatisfied>);
static_assert( cuda::std::sortable<AllConstraintsSatisfied, CompInt>);

struct Foo {};
using Proj = int(*)(Foo);
static_assert( cuda::std::permutable<Foo*>);
static_assert(!cuda::std::indirect_strict_weak_order<CompDefault, Foo*>);
static_assert( cuda::std::indirect_strict_weak_order<CompDefault, cuda::std::projected<Foo*, Proj>>);
static_assert(!cuda::std::sortable<Foo*, CompDefault>);
static_assert( cuda::std::sortable<Foo*, CompDefault, Proj>);
static_assert(!cuda::std::indirect_strict_weak_order<CompInt, Foo*>);
static_assert( cuda::std::indirect_strict_weak_order<CompInt, cuda::std::projected<Foo*, Proj>>);
static_assert(!cuda::std::sortable<Foo*, CompInt>);
static_assert( cuda::std::sortable<Foo*, CompInt, Proj>);

using NotPermutable = const int*;
static_assert(!cuda::std::permutable<NotPermutable>);
static_assert( cuda::std::indirect_strict_weak_order<CompInt, NotPermutable>);
static_assert(!cuda::std::sortable<NotPermutable, CompInt>);

struct Empty {};
using NoIndirectStrictWeakOrder = Empty*;
static_assert( cuda::std::permutable<NoIndirectStrictWeakOrder>);
static_assert(!cuda::std::indirect_strict_weak_order<CompInt, NoIndirectStrictWeakOrder>);
static_assert(!cuda::std::sortable<NoIndirectStrictWeakOrder, CompInt>);

int main(int, char**)
{
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// 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) 2023 NVIDIA CORPORATION & AFFILIATES
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// template<class I, class R = ranges::less, class P = identity>
// concept sortable = see below; // since C++20

#include <cuda/std/iterator>

#include <cuda/std/functional>

template <class I, class R, class P>
__host__ __device__ void test_subsumption() requires cuda::std::permutable<I>;

template <class I, class R, class P>
__host__ __device__ void test_subsumption() requires cuda::std::indirect_strict_weak_order<R, cuda::std::projected<I, P>>;

template <class I, class R, class P>
__host__ __device__ constexpr bool test_subsumption() requires cuda::std::sortable<I, R, P> { return true; }

static_assert(test_subsumption<int*, cuda::std::ranges::less, cuda::std::identity>());

int main(int, char**)
{
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ set(files
__iterator/reverse_access.h
__iterator/reverse_iterator.h
__iterator/size.h
__iterator/sortable.h
__iterator/wrap_iter.h
__libcpp_version
__locale
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// -*- 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) 2023 NVIDIA CORPORATION & AFFILIATES
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCUDACXX___ITERATOR_SORTABLE_H
#define _LIBCUDACXX___ITERATOR_SORTABLE_H

#ifndef __cuda_std__
#include <__config>
#endif // __cuda_std__

#include "../__functional/identity.h"
#include "../__functional/ranges_operations.h"
#include "../__iterator/concepts.h"
#include "../__iterator/permutable.h"
#include "../__iterator/projected.h"

#if defined(_LIBCUDACXX_USE_PRAGMA_GCC_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCUDACXX_BEGIN_NAMESPACE_STD

#if _LIBCUDACXX_STD_VER > 17

template <class _Iter, class _Comp = _CUDA_VRANGES::less, class _Proj = identity>
concept sortable =
permutable<_Iter> &&
indirect_strict_weak_order<_Comp, projected<_Iter, _Proj>>;

#elif _LIBCUDACXX_STD_VER > 14

template <class _Iter, class _Comp, class _Proj>
_LIBCUDACXX_CONCEPT_FRAGMENT(
__sortable_,
requires() //
(requires(permutable<_Iter>),
requires(indirect_strict_weak_order<_Comp, projected<_Iter, _Proj>>)));

template <class _Iter, class _Comp = _CUDA_VRANGES::less, class _Proj = identity>
_LIBCUDACXX_CONCEPT sortable = _LIBCUDACXX_FRAGMENT(__sortable_, _Iter, _Comp, _Proj);

#endif // _LIBCUDACXX_STD_VER > 14

_LIBCUDACXX_END_NAMESPACE_STD

#endif // _LIBCUDACXX___ITERATOR_SORTABLE_H
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
#include "__iterator/reverse_access.h"
#include "__iterator/reverse_iterator.h"
#include "__iterator/size.h"
#include "__iterator/sortable.h"
#include "__iterator/wrap_iter.h"
#include "__memory/addressof.h"
#include "__memory/pointer_traits.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// template<class I, class R = ranges::less, class P = identity>
// concept sortable = see below; // since C++20

#include <iterator>

#include <functional>

using CompInt = bool(*)(int, int);
using CompDefault = std::ranges::less;

using AllConstraintsSatisfied = int*;
static_assert( std::permutable<AllConstraintsSatisfied>);
static_assert( std::indirect_strict_weak_order<CompDefault, AllConstraintsSatisfied>);
static_assert( std::sortable<AllConstraintsSatisfied>);
static_assert( std::indirect_strict_weak_order<CompInt, AllConstraintsSatisfied>);
static_assert( std::sortable<AllConstraintsSatisfied, CompInt>);

struct Foo {};
using Proj = int(*)(Foo);
static_assert( std::permutable<Foo*>);
static_assert(!std::indirect_strict_weak_order<CompDefault, Foo*>);
static_assert( std::indirect_strict_weak_order<CompDefault, std::projected<Foo*, Proj>>);
static_assert(!std::sortable<Foo*, CompDefault>);
static_assert( std::sortable<Foo*, CompDefault, Proj>);
static_assert(!std::indirect_strict_weak_order<CompInt, Foo*>);
static_assert( std::indirect_strict_weak_order<CompInt, std::projected<Foo*, Proj>>);
static_assert(!std::sortable<Foo*, CompInt>);
static_assert( std::sortable<Foo*, CompInt, Proj>);

using NotPermutable = const int*;
static_assert(!std::permutable<NotPermutable>);
static_assert( std::indirect_strict_weak_order<CompInt, NotPermutable>);
static_assert(!std::sortable<NotPermutable, CompInt>);

struct Empty {};
using NoIndirectStrictWeakOrder = Empty*;
static_assert( std::permutable<NoIndirectStrictWeakOrder>);
static_assert(!std::indirect_strict_weak_order<CompInt, NoIndirectStrictWeakOrder>);
static_assert(!std::sortable<NoIndirectStrictWeakOrder, CompInt>);

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

// UNSUPPORTED: c++03, c++11, c++14, c++17

// template<class I, class R = ranges::less, class P = identity>
// concept sortable = see below; // since C++20

#include <iterator>

#include <functional>

template <class I, class R, class P> void test_subsumption() requires std::permutable<I>;

template <class I, class R, class P> void test_subsumption()
requires std::indirect_strict_weak_order<R, std::projected<I, P>>;

template <class I, class R, class P> constexpr bool test_subsumption() requires std::sortable<I, R, P> { return true; }

static_assert(test_subsumption<int*, std::ranges::less, std::identity>());

int main(int, char**) {
return 0;
}
Loading