Skip to content

Commit 141d3f5

Browse files
committed
Add support for <experimental/scope> header
1 parent 3817a8c commit 141d3f5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

include/nonstd/scope.hpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2020-2020 Martin Moene
2+
// Copyright (c) 2020-2025 Martin Moene
33
//
44
// https://github.com/martinmoene/scope-lite
55
//
@@ -77,24 +77,21 @@
7777
#if scope_CPP20_OR_GREATER && defined(__has_include )
7878
# if __has_include( <scope> )
7979
# define scope_HAVE_STD_SCOPE 1
80+
# define scope_HAVE_EXP_SCOPE 0
8081
# elif __has_include( <experimental/scope> )
81-
# define scope_HAVE_STD_SCOPE 1
82+
# define scope_HAVE_STD_SCOPE 0
83+
# define scope_HAVE_EXP_SCOPE 1
8284
# else
8385
# define scope_HAVE_STD_SCOPE 0
86+
# define scope_HAVE_EXP_SCOPE 0
8487
# endif
8588
#else
8689
# define scope_HAVE_STD_SCOPE 0
90+
# define scope_HAVE_EXP_SCOPE 0
8791
#endif
8892

8993
#define scope_USES_STD_SCOPE ( (scope_CONFIG_SELECT_SCOPE == scope_SCOPE_STD) || ((scope_CONFIG_SELECT_SCOPE == scope_SCOPE_DEFAULT) && scope_HAVE_STD_SCOPE) )
90-
91-
//
92-
// Using std <scope>:
93-
//
94-
// ToDo:
95-
// - choose <scope> or <experimental/scope>.
96-
// - use correct namespace in using below.
97-
//
94+
#define scope_USES_EXP_SCOPE ( (scope_CONFIG_SELECT_SCOPE == scope_SCOPE_STD) || ((scope_CONFIG_SELECT_SCOPE == scope_SCOPE_DEFAULT) && scope_HAVE_EXP_SCOPE) )
9895

9996
#if scope_USES_STD_SCOPE
10097

@@ -113,6 +110,23 @@ namespace nonstd
113110
using std::make_unique_resource_checked;
114111
}
115112

113+
#elif scope_USES_EXP_SCOPE
114+
115+
#include <experimental/scope>
116+
117+
namespace nonstd
118+
{
119+
using std::experimental::scope_exit;
120+
using std::experimental::scope_fail;
121+
using std::experimental::scope_success;
122+
using std::experimental::unique_resource;
123+
124+
using std::experimental::make_scope_exit;
125+
using std::experimental::make_scope_fail;
126+
using std::experimental::make_scope_success;
127+
using std::experimental::make_unique_resource_checked;
128+
}
129+
116130
#else // scope_USES_STD_SCOPE
117131

118132
// half-open range [lo..hi):

0 commit comments

Comments
 (0)