Skip to content

Commit 409280b

Browse files
authored
Fix C++20 macro in parallel_for_each + fix concepts macro definition (#1611)
1 parent e653e16 commit 409280b

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

include/oneapi/tbb/detail/_config.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@
233233
#if __INTEL_COMPILER && (!_MSC_VER || __INTEL_CXX11_MOVE__)
234234
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L)
235235
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__INTEL_COMPILER > 2021 && __TBB_LANG >= 201703L)
236-
#define __TBB_CPP20_CONCEPTS_PRESENT 0 // TODO: add a mechanism for future addition
237236
#elif __clang__
238237
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__has_feature(cxx_variable_templates))
239-
#define __TBB_CPP20_CONCEPTS_PRESENT 0 // TODO: add a mechanism for future addition
240238
#ifdef __cpp_deduction_guides
241239
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cpp_deduction_guides >= 201611L)
242240
#else
@@ -245,15 +243,12 @@
245243
#elif __GNUC__
246244
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L && __TBB_GCC_VERSION >= 50000)
247245
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cpp_deduction_guides >= 201606L)
248-
#define __TBB_CPP20_CONCEPTS_PRESENT (__TBB_LANG >= 201709L && __TBB_GCC_VERSION >= 100201)
249246
#elif _MSC_VER
250247
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (_MSC_FULL_VER >= 190023918 && (!__INTEL_COMPILER || __INTEL_COMPILER >= 1700))
251248
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (_MSC_VER >= 1914 && __TBB_LANG >= 201703L && (!__INTEL_COMPILER || __INTEL_COMPILER > 2021))
252-
#define __TBB_CPP20_CONCEPTS_PRESENT (_MSC_VER >= 1923 && __TBB_LANG >= 202002L) // TODO: INTEL_COMPILER?
253249
#else
254250
#define __TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__TBB_LANG >= 201402L)
255251
#define __TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__TBB_LANG >= 201703L)
256-
#define __TBB_CPP20_CONCEPTS_PRESENT (__TBB_LANG >= 202002L)
257252
#endif
258253

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

266+
// TODO: fix concepts on Clang or define the broken versions
267+
#if !(__clang__) && defined(__cpp_concepts) && defined(__cpp_lib_concepts)
268+
#define __TBB_CPP20_CONCEPTS_PRESENT ((__cpp_concepts >= 201907L) && (__cpp_lib_concepts >= 202002L))
269+
#else
270+
#define __TBB_CPP20_CONCEPTS_PRESENT 0
271+
#endif
272+
271273
#if defined(__cpp_impl_three_way_comparison) && defined(__cpp_lib_three_way_comparison)
272274
#define __TBB_CPP20_COMPARISONS_PRESENT ((__cpp_impl_three_way_comparison >= 201907L) && (__cpp_lib_three_way_comparison >= 201907L))
273275
#else

include/oneapi/tbb/detail/_range_common.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2021 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -102,20 +102,23 @@ concept tbb_range = std::copy_constructible<Range> &&
102102
{ range.is_divisible() } -> relaxed_convertible_to<bool>;
103103
};
104104

105+
template <typename Iterator, typename IteratorTag>
106+
struct iterator_concept_helper;
107+
108+
// New specializations should be added in case of using container_based_sequence with
109+
// the new iterator tag types
105110
template <typename Iterator>
106-
constexpr bool iterator_concept_helper( std::input_iterator_tag ) {
107-
return std::input_iterator<Iterator>;
108-
}
111+
struct iterator_concept_helper<Iterator, std::input_iterator_tag> {
112+
static constexpr bool value = std::input_iterator<Iterator>;
113+
};
109114

110115
template <typename Iterator>
111-
constexpr bool iterator_concept_helper( std::random_access_iterator_tag ) {
112-
return std::random_access_iterator<Iterator>;
113-
}
116+
struct iterator_concept_helper<Iterator, std::random_access_iterator_tag> {
117+
static constexpr bool value = std::random_access_iterator<Iterator>;
118+
};
114119

115120
template <typename Iterator, typename IteratorTag>
116-
concept iterator_satisfies = requires (IteratorTag tag) {
117-
requires iterator_concept_helper<Iterator>(tag);
118-
};
121+
concept iterator_satisfies = iterator_concept_helper<Iterator, IteratorTag>::value;
119122

120123
template <typename Sequence, typename IteratorTag>
121124
concept container_based_sequence = requires( Sequence& seq ) {

include/oneapi/tbb/flow_graph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2024 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@ class continue_msg {};
8585
} // namespace d2
8686

8787
#if __TBB_CPP20_CONCEPTS_PRESENT
88-
namespace d0 {
88+
inline namespace d0 {
8989

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

130-
} // namespace d0
130+
} // inline namespace d0
131131
#endif // __TBB_CPP20_CONCEPTS_PRESENT
132132

133133
namespace d2 {

include/oneapi/tbb/parallel_for_each.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2024 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -409,7 +409,7 @@ class parallel_for_body_wrapper {
409409
template<typename It>
410410
using tag = typename std::iterator_traits<It>::iterator_category;
411411

412-
#if __TBB_CPP20_PRESENT
412+
#if __TBB_CPP20_CONCEPTS_PRESENT
413413
template <typename It>
414414
struct move_iterator_dispatch_helper {
415415
using type = It;
@@ -448,7 +448,7 @@ using iterator_tag_dispatch = typename
448448
std::input_iterator_tag
449449
>::type
450450
>::type;
451-
#endif // __TBB_CPP20_PRESENT
451+
#endif // __TBB_CPP20_CONCEPTS_PRESENT
452452

453453
template <typename Body, typename Iterator, typename Item>
454454
using feeder_is_required = tbb::detail::void_t<decltype(tbb::detail::invoke(std::declval<const Body>(),

include/oneapi/tbb/parallel_scan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2024 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ struct sum_node;
5252

5353
#if __TBB_CPP20_CONCEPTS_PRESENT
5454
} // namespace d1
55-
namespace d0 {
55+
inline namespace d0 {
5656

5757
template <typename Body, typename Range>
5858
concept parallel_scan_body = splittable<Body> &&

test/common/concepts_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2021 Intel Corporation
2+
Copyright (c) 2021-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -385,7 +385,7 @@ struct ParallelScanFunction {
385385
T operator()( Dummy, const T& a, bool ) const requires (EnableFunctionCallOperator == State::incorrect_first_input) { return a; }
386386
T operator()( const Range&, Dummy, bool ) const requires (EnableFunctionCallOperator == State::incorrect_second_input) { return T{}; }
387387
T operator()( const Range&, const T& a, Dummy ) const requires (EnableFunctionCallOperator == State::incorrect_third_input) { return a; }
388-
Dummy operator()( const Range&, const T& a, bool ) const requires (EnableFunctionCallOperator == State::incorrect_return_type) { return Dummy{}; }
388+
Dummy operator()( const Range&, const T&, bool ) const requires (EnableFunctionCallOperator == State::incorrect_return_type) { return Dummy{}; }
389389
};
390390

391391
template <typename R, typename T> using Correct = ParallelScanFunction<R, T, /*() = */State::correct>;

test/tbb/test_parallel_for_each.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005-2023 Intel Corporation
2+
Copyright (c) 2005-2025 Intel Corporation
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
//! \file test_parallel_for_each.cpp
2323
//! \brief Test for [algorithms.parallel_for_each]
2424

25-
#if __TBB_CPP20_PRESENT
25+
#if __TBB_CPP20_CONCEPTS_PRESENT
2626
// Fancy iterator type that models the C++20 iterator type
2727
// that defines the real iterator category using iterator_concept type
2828
// and iterator_category is always std::input_iterator_type
@@ -119,7 +119,7 @@ struct cpp20_iterator {
119119
private:
120120
T* my_ptr = nullptr;
121121
}; // class cpp20_iterator
122-
#endif // __TBB_CPP20_PRESENT
122+
#endif // __TBB_CPP20_CONCEPTS_PRESENT
123123

124124
//! Test forward access iterator support
125125
//! \brief \ref error_guessing \ref interface
@@ -270,10 +270,6 @@ TEST_CASE("parallel_for_each constraints") {
270270
test_pfor_each_body_constraints();
271271
}
272272

273-
#endif // __TBB_CPP20_CONCEPTS_PRESENT
274-
275-
#if __TBB_CPP20_PRESENT
276-
277273
struct no_copy_move {
278274
no_copy_move() = default;
279275

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

335-
#endif // __TBB_CPP20_PRESENT
331+
#endif // __TBB_CPP20_CONCEPTS_PRESENT

0 commit comments

Comments
 (0)