35
35
36
36
#ifndef _MSC_VER
37
37
// This is the ideal -- note that we just voted "import std;"
38
- // into draft C++23 in late July 2022, so implementers haven't
38
+ // into draft C++23 in late July 2022, so implementers haven't
39
39
// had time to catch up yet. As of this writing (September 2022)
40
40
// no compiler will take this path yet, but they're on the way...
41
41
import std;
204
204
namespace cpp2 {
205
205
206
206
// -----------------------------------------------------------------------
207
- //
207
+ //
208
208
// contract_group
209
- //
209
+ //
210
210
// -----------------------------------------------------------------------
211
211
//
212
212
@@ -255,30 +255,30 @@ class contract_group {
255
255
std::terminate ();
256
256
}
257
257
258
- auto inline Default = contract_group(
259
- [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
258
+ auto inline Default = contract_group(
259
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
260
260
report_and_terminate (" Contract" , msg CPP2_SOURCE_LOCATION_ARG);
261
261
}
262
262
);
263
- auto inline Bounds = contract_group(
264
- [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
263
+ auto inline Bounds = contract_group(
264
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
265
265
report_and_terminate (" Bounds safety" , msg CPP2_SOURCE_LOCATION_ARG);
266
- }
266
+ }
267
267
);
268
- auto inline Null = contract_group(
269
- [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
268
+ auto inline Null = contract_group(
269
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
270
270
report_and_terminate (" Null safety" , msg CPP2_SOURCE_LOCATION_ARG);
271
- }
271
+ }
272
272
);
273
- auto inline Type = contract_group(
274
- [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
273
+ auto inline Type = contract_group(
274
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
275
275
report_and_terminate (" Type safety" , msg CPP2_SOURCE_LOCATION_ARG);
276
- }
276
+ }
277
277
);
278
- auto inline Testing = contract_group(
279
- [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
278
+ auto inline Testing = contract_group(
279
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
280
280
report_and_terminate (" Testing" , msg CPP2_SOURCE_LOCATION_ARG);
281
- }
281
+ }
282
282
);
283
283
284
284
constexpr auto contract_group::set_handler (handler h) -> handler {
@@ -317,12 +317,12 @@ auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAU
317
317
318
318
319
319
// -----------------------------------------------------------------------
320
- //
320
+ //
321
321
// Arena objects for std::allocators
322
- //
322
+ //
323
323
// Note: cppfront translates "new" to "cpp2_new", so in Cpp2 code
324
324
// these are invoked by simply "unique.new<T>" etc.
325
- //
325
+ //
326
326
// -----------------------------------------------------------------------
327
327
//
328
328
struct {
@@ -346,13 +346,13 @@ template<typename T, typename... Args>
346
346
347
347
348
348
// -----------------------------------------------------------------------
349
- //
349
+ //
350
350
// in<T> For "in" parameter
351
- //
351
+ //
352
352
// -----------------------------------------------------------------------
353
353
//
354
354
template <typename T>
355
- using in =
355
+ using in =
356
356
std::conditional_t <
357
357
sizeof (T) < 2 *sizeof (void *) && std::is_trivially_copy_constructible_v<T>,
358
358
T const ,
@@ -361,19 +361,19 @@ using in =
361
361
362
362
363
363
// -----------------------------------------------------------------------
364
- //
364
+ //
365
365
// Initialization: These are closely related...
366
- //
366
+ //
367
367
// deferred_init<T> For deferred-initialized local or member variable
368
368
//
369
369
// out<T> For out parameter
370
- //
370
+ //
371
371
// -----------------------------------------------------------------------
372
372
//
373
373
template <typename T>
374
374
class deferred_init {
375
375
bool init = false ;
376
- union {
376
+ union {
377
377
int i;
378
378
T t;
379
379
};
@@ -414,7 +414,7 @@ class out {
414
414
}
415
415
}
416
416
417
- auto construct (auto ...args) -> void {
417
+ auto construct (auto ...args) -> void {
418
418
if (has_t ) {
419
419
*t = T (args...);
420
420
}
@@ -427,7 +427,7 @@ class out {
427
427
}
428
428
}
429
429
430
- auto construct_list (auto ...args) -> void {
430
+ auto construct_list (auto ...args) -> void {
431
431
if (has_t ) {
432
432
*t = T{args...};
433
433
}
@@ -443,9 +443,9 @@ class out {
443
443
444
444
445
445
// -----------------------------------------------------------------------
446
- //
446
+ //
447
447
// CPP2_UFCS: Variadic macro generating a variadic lamba, oh my...
448
- //
448
+ //
449
449
// -----------------------------------------------------------------------
450
450
//
451
451
#define CPP2_UFCS (FUNCNAME,PARAM1,...) \
@@ -468,9 +468,9 @@ class out {
468
468
469
469
470
470
// -----------------------------------------------------------------------
471
- //
471
+ //
472
472
// is and as
473
- //
473
+ //
474
474
// -----------------------------------------------------------------------
475
475
//
476
476
// -------------------------------------------------------------------------------------------------------------
@@ -526,7 +526,7 @@ auto as( X const& x ) -> auto&& {
526
526
}
527
527
528
528
template < typename C, typename X >
529
- auto as ( X const & x ) -> auto
529
+ auto as ( X const & x ) -> auto
530
530
requires (!std::is_same_v<C, X> && requires { C{x}; })
531
531
{
532
532
return C{x};
@@ -640,18 +640,18 @@ constexpr auto as( X const& x ) -> auto&&
640
640
641
641
642
642
// -----------------------------------------------------------------------
643
- //
643
+ //
644
644
// A variation of GSL's final_action_success and finally to run only on success
645
645
// (based on a PR I contributed to Microsoft GSL)
646
- //
646
+ //
647
647
// final_action_success_success ensures something is run at the end of a scope
648
648
// if no exception is thrown
649
- //
649
+ //
650
650
// finally_success is a convenience function to make a final_action_success_success
651
- //
651
+ //
652
652
// -----------------------------------------------------------------------
653
653
//
654
-
654
+
655
655
template <class F >
656
656
class final_action_success
657
657
{
@@ -688,9 +688,9 @@ template <class F>
688
688
689
689
690
690
// -----------------------------------------------------------------------
691
- //
691
+ //
692
692
// to_string for string interpolation
693
- //
693
+ //
694
694
// -----------------------------------------------------------------------
695
695
//
696
696
template <typename T>
@@ -725,18 +725,18 @@ using cpp2::cpp2_new;
725
725
726
726
727
727
// -----------------------------------------------------------------------
728
- //
728
+ //
729
729
// A partial implementation of GSL features Cpp2 relies on,
730
730
// to keep this a standalone header without non-std dependencies
731
- //
731
+ //
732
732
// -----------------------------------------------------------------------
733
733
//
734
734
namespace gsl {
735
735
736
736
// -----------------------------------------------------------------------
737
- //
737
+ //
738
738
// An implementation of GSL's narrow_cast
739
- //
739
+ //
740
740
// -----------------------------------------------------------------------
741
741
//
742
742
template <typename To, typename From>
0 commit comments