Skip to content

Commit 6fbd21d

Browse files
Provide libcu++ transparent functors in C++11
Addresses part of: #1664
1 parent bab3b8c commit 6fbd21d

24 files changed

+6
-137
lines changed

libcudacxx/include/cuda/std/__functional/operations.h

+1-93
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55
// See https://llvm.org/LICENSE.txt for license information.
66
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7-
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
7+
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
88
//
99
//===----------------------------------------------------------------------===//
1010

@@ -55,11 +55,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus<void>
5555
typedef void is_transparent;
5656
};
5757

58-
#if _CCCL_STD_VER > 2011
5958
template <class _Tp = void>
60-
#else
61-
template <class _Tp>
62-
#endif
6359
struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp>
6460
{
6561
typedef _Tp __result_type; // used by valarray
@@ -71,7 +67,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp>
7167
};
7268
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(minus);
7369

74-
#if _CCCL_STD_VER > 2011
7570
template <>
7671
struct _LIBCUDACXX_TEMPLATE_VIS minus<void>
7772
{
@@ -85,7 +80,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus<void>
8580
}
8681
typedef void is_transparent;
8782
};
88-
#endif
8983

9084
template <class _Tp = void>
9185
struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp>
@@ -113,11 +107,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies<void>
113107
typedef void is_transparent;
114108
};
115109

116-
#if _CCCL_STD_VER > 2011
117110
template <class _Tp = void>
118-
#else
119-
template <class _Tp>
120-
#endif
121111
struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp>
122112
{
123113
typedef _Tp __result_type; // used by valarray
@@ -129,7 +119,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp>
129119
};
130120
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(divides);
131121

132-
#if _CCCL_STD_VER > 2011
133122
template <>
134123
struct _LIBCUDACXX_TEMPLATE_VIS divides<void>
135124
{
@@ -143,13 +132,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides<void>
143132
}
144133
typedef void is_transparent;
145134
};
146-
#endif
147135

148-
#if _CCCL_STD_VER > 2011
149136
template <class _Tp = void>
150-
#else
151-
template <class _Tp>
152-
#endif
153137
struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp>
154138
{
155139
typedef _Tp __result_type; // used by valarray
@@ -161,7 +145,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp>
161145
};
162146
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(modulus);
163147

164-
#if _CCCL_STD_VER > 2011
165148
template <>
166149
struct _LIBCUDACXX_TEMPLATE_VIS modulus<void>
167150
{
@@ -175,7 +158,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus<void>
175158
}
176159
typedef void is_transparent;
177160
};
178-
#endif
179161

180162
template <class _Tp = void>
181163
struct _LIBCUDACXX_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp>
@@ -204,11 +186,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS negate<void>
204186

205187
// Bitwise operations
206188

207-
#if _CCCL_STD_VER > 2011
208189
template <class _Tp = void>
209-
#else
210-
template <class _Tp>
211-
#endif
212190
struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp>
213191
{
214192
typedef _Tp __result_type; // used by valarray
@@ -220,7 +198,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp>
220198
};
221199
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_and);
222200

223-
#if _CCCL_STD_VER > 2011
224201
template <>
225202
struct _LIBCUDACXX_TEMPLATE_VIS bit_and<void>
226203
{
@@ -234,9 +211,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and<void>
234211
}
235212
typedef void is_transparent;
236213
};
237-
#endif
238214

239-
#if _CCCL_STD_VER > 2011
240215
template <class _Tp = void>
241216
struct _LIBCUDACXX_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp>
242217
{
@@ -260,13 +235,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_not<void>
260235
}
261236
typedef void is_transparent;
262237
};
263-
#endif
264238

265-
#if _CCCL_STD_VER > 2011
266239
template <class _Tp = void>
267-
#else
268-
template <class _Tp>
269-
#endif
270240
struct _LIBCUDACXX_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp>
271241
{
272242
typedef _Tp __result_type; // used by valarray
@@ -278,7 +248,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp>
278248
};
279249
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_or);
280250

281-
#if _CCCL_STD_VER > 2011
282251
template <>
283252
struct _LIBCUDACXX_TEMPLATE_VIS bit_or<void>
284253
{
@@ -292,13 +261,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_or<void>
292261
}
293262
typedef void is_transparent;
294263
};
295-
#endif
296264

297-
#if _CCCL_STD_VER > 2011
298265
template <class _Tp = void>
299-
#else
300-
template <class _Tp>
301-
#endif
302266
struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp>
303267
{
304268
typedef _Tp __result_type; // used by valarray
@@ -310,7 +274,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp>
310274
};
311275
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_xor);
312276

313-
#if _CCCL_STD_VER > 2011
314277
template <>
315278
struct _LIBCUDACXX_TEMPLATE_VIS bit_xor<void>
316279
{
@@ -324,15 +287,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor<void>
324287
}
325288
typedef void is_transparent;
326289
};
327-
#endif
328290

329291
// Comparison operations
330292

331-
#if _CCCL_STD_VER > 2011
332293
template <class _Tp = void>
333-
#else
334-
template <class _Tp>
335-
#endif
336294
struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool>
337295
{
338296
typedef bool __result_type; // used by valarray
@@ -344,7 +302,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool>
344302
};
345303
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(equal_to);
346304

347-
#if _CCCL_STD_VER > 2011
348305
template <>
349306
struct _LIBCUDACXX_TEMPLATE_VIS equal_to<void>
350307
{
@@ -358,13 +315,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to<void>
358315
}
359316
typedef void is_transparent;
360317
};
361-
#endif
362318

363-
#if _CCCL_STD_VER > 2011
364319
template <class _Tp = void>
365-
#else
366-
template <class _Tp>
367-
#endif
368320
struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool>
369321
{
370322
typedef bool __result_type; // used by valarray
@@ -376,7 +328,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool>
376328
};
377329
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);
378330

379-
#if _CCCL_STD_VER > 2011
380331
template <>
381332
struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to<void>
382333
{
@@ -390,13 +341,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to<void>
390341
}
391342
typedef void is_transparent;
392343
};
393-
#endif
394344

395-
#if _CCCL_STD_VER > 2011
396345
template <class _Tp = void>
397-
#else
398-
template <class _Tp>
399-
#endif
400346
struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool>
401347
{
402348
typedef bool __result_type; // used by valarray
@@ -408,7 +354,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool>
408354
};
409355
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less);
410356

411-
#if _CCCL_STD_VER > 2011
412357
template <>
413358
struct _LIBCUDACXX_TEMPLATE_VIS less<void>
414359
{
@@ -422,13 +367,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS less<void>
422367
}
423368
typedef void is_transparent;
424369
};
425-
#endif
426370

427-
#if _CCCL_STD_VER > 2011
428371
template <class _Tp = void>
429-
#else
430-
template <class _Tp>
431-
#endif
432372
struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool>
433373
{
434374
typedef bool __result_type; // used by valarray
@@ -440,7 +380,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool>
440380
};
441381
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less_equal);
442382

443-
#if _CCCL_STD_VER > 2011
444383
template <>
445384
struct _LIBCUDACXX_TEMPLATE_VIS less_equal<void>
446385
{
@@ -454,13 +393,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal<void>
454393
}
455394
typedef void is_transparent;
456395
};
457-
#endif
458396

459-
#if _CCCL_STD_VER > 2011
460397
template <class _Tp = void>
461-
#else
462-
template <class _Tp>
463-
#endif
464398
struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool>
465399
{
466400
typedef bool __result_type; // used by valarray
@@ -472,7 +406,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool
472406
};
473407
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater_equal);
474408

475-
#if _CCCL_STD_VER > 2011
476409
template <>
477410
struct _LIBCUDACXX_TEMPLATE_VIS greater_equal<void>
478411
{
@@ -486,13 +419,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal<void>
486419
}
487420
typedef void is_transparent;
488421
};
489-
#endif
490422

491-
#if _CCCL_STD_VER > 2011
492423
template <class _Tp = void>
493-
#else
494-
template <class _Tp>
495-
#endif
496424
struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool>
497425
{
498426
typedef bool __result_type; // used by valarray
@@ -504,7 +432,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool>
504432
};
505433
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater);
506434

507-
#if _CCCL_STD_VER > 2011
508435
template <>
509436
struct _LIBCUDACXX_TEMPLATE_VIS greater<void>
510437
{
@@ -518,15 +445,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater<void>
518445
}
519446
typedef void is_transparent;
520447
};
521-
#endif
522448

523449
// Logical operations
524450

525-
#if _CCCL_STD_VER > 2011
526451
template <class _Tp = void>
527-
#else
528-
template <class _Tp>
529-
#endif
530452
struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool>
531453
{
532454
typedef bool __result_type; // used by valarray
@@ -538,7 +460,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool>
538460
};
539461
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_and);
540462

541-
#if _CCCL_STD_VER > 2011
542463
template <>
543464
struct _LIBCUDACXX_TEMPLATE_VIS logical_and<void>
544465
{
@@ -552,13 +473,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and<void>
552473
}
553474
typedef void is_transparent;
554475
};
555-
#endif
556476

557-
#if _CCCL_STD_VER > 2011
558477
template <class _Tp = void>
559-
#else
560-
template <class _Tp>
561-
#endif
562478
struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool>
563479
{
564480
typedef bool __result_type; // used by valarray
@@ -570,7 +486,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool>
570486
};
571487
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_not);
572488

573-
#if _CCCL_STD_VER > 2011
574489
template <>
575490
struct _LIBCUDACXX_TEMPLATE_VIS logical_not<void>
576491
{
@@ -583,13 +498,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_not<void>
583498
}
584499
typedef void is_transparent;
585500
};
586-
#endif
587501

588-
#if _CCCL_STD_VER > 2011
589502
template <class _Tp = void>
590-
#else
591-
template <class _Tp>
592-
#endif
593503
struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool>
594504
{
595505
typedef bool __result_type; // used by valarray
@@ -601,7 +511,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool>
601511
};
602512
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_or);
603513

604-
#if _CCCL_STD_VER > 2011
605514
template <>
606515
struct _LIBCUDACXX_TEMPLATE_VIS logical_or<void>
607516
{
@@ -615,7 +524,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or<void>
615524
}
616525
typedef void is_transparent;
617526
};
618-
#endif
619527

620528
_LIBCUDACXX_END_NAMESPACE_STD
621529

libcudacxx/test/libcudacxx/std/utilities/function.objects/arithmetic.operations/divides.pass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ int main(int, char**)
4747
static_assert((cuda::std::is_same<int, F::result_type>::value), "");
4848
#endif
4949
assert(f(36, 4) == 9);
50-
#if TEST_STD_VER > 2011
5150
typedef cuda::std::divides<> F2;
5251
const F2 f2 = F2();
5352
assert(f2(36, 4) == 9);
@@ -59,7 +58,6 @@ int main(int, char**)
5958

6059
constexpr double bar = cuda::std::divides<>()(3.0, 2);
6160
static_assert(bar == 1.5, ""); // exact in binary
62-
#endif
6361

6462
return 0;
6563
}

0 commit comments

Comments
 (0)