diff options
| author | Tyge Løvset <[email protected]> | 2023-05-13 11:04:11 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-05-13 11:04:11 +0200 |
| commit | be7d9913d4a284bdeb7f0431482b5731b5ef31df (patch) | |
| tree | 92ab761056a60961827b0025768bad9870fbc24c /include | |
| parent | 98d131bfc1bcc8b82cb27b30ad6da176d1fed117 (diff) | |
| download | STC-modified-be7d9913d4a284bdeb7f0431482b5731b5ef31df.tar.gz STC-modified-be7d9913d4a284bdeb7f0431482b5731b5ef31df.zip | |
File priv/raii.h no longer included by stc/ccommon.h, instead moved to stc/algo/raii.h and included by stc/calgo.h
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/algo/raii.h | 54 | ||||
| -rw-r--r-- | include/stc/calgo.h | 1 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 3 | ||||
| -rw-r--r-- | include/stc/priv/raii.h | 27 |
4 files changed, 56 insertions, 29 deletions
diff --git a/include/stc/algo/raii.h b/include/stc/algo/raii.h new file mode 100644 index 00000000..7b1b445b --- /dev/null +++ b/include/stc/algo/raii.h @@ -0,0 +1,54 @@ +/* MIT License + * + * Copyright (c) 2023 Tyge Løvset + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. +*/ +#ifndef STC_RAII_INCLUDED +#define STC_RAII_INCLUDED + +#define c_defer(...) \ + for (int _i = 1; _i; _i = 0, __VA_ARGS__) + +#define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__) +#define c_with_2(declvar, drop) \ + for (declvar, *_i, **_ip = &_i; _ip; _ip = 0, drop) +#define c_with_3(declvar, pred, drop) \ + for (declvar, *_i, **_ip = &_i; _ip && (pred); _ip = 0, drop) + +#define c_scope(...) c_MACRO_OVERLOAD(c_scope, __VA_ARGS__) +#define c_scope_2(init, drop) \ + for (int _i = (init, 1); _i; _i = 0, drop) +#define c_scope_3(init, pred, drop) \ + for (int _i = (init, 1); _i && (pred); _i = 0, drop) + +#define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__) +#define c_auto_2(C, a) \ + c_with_2(C a = C##_init(), C##_drop(&a)) +#define c_auto_3(C, a, b) \ + c_with_2(c_EXPAND(C a = C##_init(), b = C##_init()), \ + (C##_drop(&b), C##_drop(&a))) +#define c_auto_4(C, a, b, c) \ + c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \ + (C##_drop(&c), C##_drop(&b), C##_drop(&a))) +#define c_auto_5(C, a, b, c, d) \ + c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \ + (C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a))) + +#endif
\ No newline at end of file diff --git a/include/stc/calgo.h b/include/stc/calgo.h index 21e73faf..63ef97b9 100644 --- a/include/stc/calgo.h +++ b/include/stc/calgo.h @@ -1,6 +1,7 @@ #ifndef STC_CALGO_INCLUDED #define STC_CALGO_INCLUDED +#include "algo/raii.h" #include "algo/crange.h" #include "algo/filter.h" #include "algo/coroutine.h" diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 1882646c..fd673696 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -29,7 +29,6 @@ #include <stdbool.h> #include <string.h> #include <assert.h> -#include "priv/raii.h" #define c_NPOS INTPTR_MAX #define c_ZI PRIiPTR @@ -62,7 +61,7 @@ #define _c_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \ _14, _15, _16, N, ...) N -#ifdef __cplusplus +#ifdef __cplusplus #include <new> #define _i_alloc(T) static_cast<T*>(i_malloc(c_sizeof(T))) #define _i_new(T, ...) new (_i_alloc(T)) T(__VA_ARGS__) diff --git a/include/stc/priv/raii.h b/include/stc/priv/raii.h deleted file mode 100644 index bb41e0d1..00000000 --- a/include/stc/priv/raii.h +++ /dev/null @@ -1,27 +0,0 @@ -#define c_defer(...) \ - for (int _i = 1; _i; _i = 0, __VA_ARGS__) - -#define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__) -#define c_with_2(declvar, drop) \ - for (declvar, *_i, **_ip = &_i; _ip; _ip = 0, drop) -#define c_with_3(declvar, pred, drop) \ - for (declvar, *_i, **_ip = &_i; _ip && (pred); _ip = 0, drop) - -#define c_scope(...) c_MACRO_OVERLOAD(c_scope, __VA_ARGS__) -#define c_scope_2(init, drop) \ - for (int _i = (init, 1); _i; _i = 0, drop) -#define c_scope_3(init, pred, drop) \ - for (int _i = (init, 1); _i && (pred); _i = 0, drop) - -#define c_auto(...) c_MACRO_OVERLOAD(c_auto, __VA_ARGS__) -#define c_auto_2(C, a) \ - c_with_2(C a = C##_init(), C##_drop(&a)) -#define c_auto_3(C, a, b) \ - c_with_2(c_EXPAND(C a = C##_init(), b = C##_init()), \ - (C##_drop(&b), C##_drop(&a))) -#define c_auto_4(C, a, b, c) \ - c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init()), \ - (C##_drop(&c), C##_drop(&b), C##_drop(&a))) -#define c_auto_5(C, a, b, c, d) \ - c_with_2(c_EXPAND(C a = C##_init(), b = C##_init(), c = C##_init(), d = C##_init()), \ - (C##_drop(&d), C##_drop(&c), C##_drop(&b), C##_drop(&a))) |
