Skip to content

Commit

Permalink
Fix C++20 macro in parallel_for_each + fix concepts macro definition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kboyarinov authored Jan 31, 2025
1 parent e653e16 commit 409280b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
12 changes: 7 additions & 5 deletions include/oneapi/tbb/detail/_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,8 @@
#if __INTEL_COMPILER && (!_MSC_VER || __INTEL_CXX11_MOVE__)
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L)
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__INTEL_COMPILER > 2021 && __TBB_LANG >= 201703L)
#define __TBB_CPP20_CONCEPTS_PRESENT 0 // TODO: add a mechanism for future addition
#elif __clang__
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__has_feature(cxx_variable_templates))
#define __TBB_CPP20_CONCEPTS_PRESENT 0 // TODO: add a mechanism for future addition
#ifdef __cpp_deduction_guides
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cpp_deduction_guides >= 201611L)
#else
Expand All @@ -245,15 +243,12 @@
#elif __GNUC__
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L && __TBB_GCC_VERSION >= 50000)
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cpp_deduction_guides >= 201606L)
#define __TBB_CPP20_CONCEPTS_PRESENT (__TBB_LANG >= 201709L && __TBB_GCC_VERSION >= 100201)
#elif _MSC_VER
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (_MSC_FULL_VER >= 190023918 && (!__INTEL_COMPILER || __INTEL_COMPILER >= 1700))
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (_MSC_VER >= 1914 && __TBB_LANG >= 201703L && (!__INTEL_COMPILER || __INTEL_COMPILER > 2021))
#define __TBB_CPP20_CONCEPTS_PRESENT (_MSC_VER >= 1923 && __TBB_LANG >= 202002L) // TODO: INTEL_COMPILER?
#else
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L)
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__TBB_LANG >= 201703L)
#define __TBB_CPP20_CONCEPTS_PRESENT (__TBB_LANG >= 202002L)
#endif

// GCC4.8 on RHEL7 does not support std::get_new_handler
Expand All @@ -268,6 +263,13 @@
#define __TBB_CPP17_ALLOCATOR_IS_ALWAYS_EQUAL_PRESENT (__TBB_LANG >= 201703L)
#define __TBB_CPP17_IS_SWAPPABLE_PRESENT (__TBB_LANG >= 201703L)

// TODO: fix concepts on Clang or define the broken versions
#if !(__clang__) && defined(__cpp_concepts) && defined(__cpp_lib_concepts)
#define __TBB_CPP20_CONCEPTS_PRESENT ((__cpp_concepts >= 201907L) && (__cpp_lib_concepts >= 202002L))
#else
#define __TBB_CPP20_CONCEPTS_PRESENT 0
#endif

#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_three_way_comparison)
#define __TBB_CPP20_COMPARISONS_PRESENT ((__cpp_impl_three_way_comparison >= 201907L) && (__cpp_lib_three_way_comparison >= 201907L))
#else
Expand Down
23 changes: 13 additions & 10 deletions include/oneapi/tbb/detail/_range_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2021 Intel Corporation
Copyright (c) 2005-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -102,20 +102,23 @@ concept tbb_range = std::copy_constructible<Range> &&
{ range.is_divisible() } -> relaxed_convertible_to<bool>;
};

template <typename Iterator, typename IteratorTag>
struct iterator_concept_helper;

// New specializations should be added in case of using container_based_sequence with
// the new iterator tag types
template <typename Iterator>
constexpr bool iterator_concept_helper( std::input_iterator_tag ) {
return std::input_iterator<Iterator>;
}
struct iterator_concept_helper<Iterator, std::input_iterator_tag> {
static constexpr bool value = std::input_iterator<Iterator>;
};

template <typename Iterator>
constexpr bool iterator_concept_helper( std::random_access_iterator_tag ) {
return std::random_access_iterator<Iterator>;
}
struct iterator_concept_helper<Iterator, std::random_access_iterator_tag> {
static constexpr bool value = std::random_access_iterator<Iterator>;
};

template <typename Iterator, typename IteratorTag>
concept iterator_satisfies = requires (IteratorTag tag) {
requires iterator_concept_helper<Iterator>(tag);
};
concept iterator_satisfies = iterator_concept_helper<Iterator, IteratorTag>::value;

template <typename Sequence, typename IteratorTag>
concept container_based_sequence = requires( Sequence& seq ) {
Expand Down
6 changes: 3 additions & 3 deletions include/oneapi/tbb/flow_graph.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2024 Intel Corporation
Copyright (c) 2005-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -85,7 +85,7 @@ class continue_msg {};
} // namespace d2

#if __TBB_CPP20_CONCEPTS_PRESENT
namespace d0 {
inline namespace d0 {

template <typename ReturnType, typename OutputType>
concept node_body_return_type = std::same_as<OutputType, tbb::detail::d2::continue_msg> ||
Expand Down Expand Up @@ -127,7 +127,7 @@ template <typename Body, typename Input, typename GatewayType>
concept async_node_body = std::copy_constructible<Body> &&
std::invocable<Body&, const Input&, GatewayType&>;

} // namespace d0
} // inline namespace d0
#endif // __TBB_CPP20_CONCEPTS_PRESENT

namespace d2 {
Expand Down
6 changes: 3 additions & 3 deletions include/oneapi/tbb/parallel_for_each.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2024 Intel Corporation
Copyright (c) 2005-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -409,7 +409,7 @@ class parallel_for_body_wrapper {
template<typename It>
using tag = typename std::iterator_traits<It>::iterator_category;

#if __TBB_CPP20_PRESENT
#if __TBB_CPP20_CONCEPTS_PRESENT
template <typename It>
struct move_iterator_dispatch_helper {
using type = It;
Expand Down Expand Up @@ -448,7 +448,7 @@ using iterator_tag_dispatch = typename
std::input_iterator_tag
>::type
>::type;
#endif // __TBB_CPP20_PRESENT
#endif // __TBB_CPP20_CONCEPTS_PRESENT

template <typename Body, typename Iterator, typename Item>
using feeder_is_required = tbb::detail::void_t<decltype(tbb::detail::invoke(std::declval<const Body>(),
Expand Down
4 changes: 2 additions & 2 deletions include/oneapi/tbb/parallel_scan.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2024 Intel Corporation
Copyright (c) 2005-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ struct sum_node;

#if __TBB_CPP20_CONCEPTS_PRESENT
} // namespace d1
namespace d0 {
inline namespace d0 {

template <typename Body, typename Range>
concept parallel_scan_body = splittable<Body> &&
Expand Down
4 changes: 2 additions & 2 deletions test/common/concepts_common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2021 Intel Corporation
Copyright (c) 2021-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -385,7 +385,7 @@ struct ParallelScanFunction {
T operator()( Dummy, const T& a, bool ) const requires (EnableFunctionCallOperator == State::incorrect_first_input) { return a; }
T operator()( const Range&, Dummy, bool ) const requires (EnableFunctionCallOperator == State::incorrect_second_input) { return T{}; }
T operator()( const Range&, const T& a, Dummy ) const requires (EnableFunctionCallOperator == State::incorrect_third_input) { return a; }
Dummy operator()( const Range&, const T& a, bool ) const requires (EnableFunctionCallOperator == State::incorrect_return_type) { return Dummy{}; }
Dummy operator()( const Range&, const T&, bool ) const requires (EnableFunctionCallOperator == State::incorrect_return_type) { return Dummy{}; }
};

template <typename R, typename T> using Correct = ParallelScanFunction<R, T, /*() = */State::correct>;
Expand Down
12 changes: 4 additions & 8 deletions test/tbb/test_parallel_for_each.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005-2023 Intel Corporation
Copyright (c) 2005-2025 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@
//! \file test_parallel_for_each.cpp
//! \brief Test for [algorithms.parallel_for_each]

#if __TBB_CPP20_PRESENT
#if __TBB_CPP20_CONCEPTS_PRESENT
// Fancy iterator type that models the C++20 iterator type
// that defines the real iterator category using iterator_concept type
// and iterator_category is always std::input_iterator_type
Expand Down Expand Up @@ -119,7 +119,7 @@ struct cpp20_iterator {
private:
T* my_ptr = nullptr;
}; // class cpp20_iterator
#endif // __TBB_CPP20_PRESENT
#endif // __TBB_CPP20_CONCEPTS_PRESENT

//! Test forward access iterator support
//! \brief \ref error_guessing \ref interface
Expand Down Expand Up @@ -270,10 +270,6 @@ TEST_CASE("parallel_for_each constraints") {
test_pfor_each_body_constraints();
}

#endif // __TBB_CPP20_CONCEPTS_PRESENT

#if __TBB_CPP20_PRESENT

struct no_copy_move {
no_copy_move() = default;

Expand Down Expand Up @@ -332,4 +328,4 @@ TEST_CASE("parallel_for_each with cpp20 iterator") {
test_with_cpp20_iterator<std::random_access_iterator_tag>();
}

#endif // __TBB_CPP20_PRESENT
#endif // __TBB_CPP20_CONCEPTS_PRESENT

0 comments on commit 409280b

Please sign in to comment.