Skip to content

Commit f89e095

Browse files
more pro forma changes before graduation (#19)
* more pro forma changes before graduation * responding to comments
1 parent f4fbd65 commit f89e095

File tree

5 files changed

+106
-13
lines changed

5 files changed

+106
-13
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"/polyfill/i",
3434
"/autosar/i",
3535
"/__cplusplus/",
36-
"/<cassert>/"
36+
"/<cassert>/",
37+
"/godbolt/i",
38+
"/cppreference/"
3739
],
3840
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
3941
"cmake.configureOnOpen": false,

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Proposing a New Type
2+
3+
If you want to add to CETL you should start on the [forum](https://forum.opencyphal.org/c/app/cetl/22). Once we have
4+
tacit approval the type should be developed using a [standard Github workflow](https://docs.github.com/en/get-started/quickstart/contributing-to-projects).
5+
6+
> Please don't write code on the forum. The forum post should be used to build consensus that a given type should be
7+
developed and contributed to CETL before you go wasting your time writing the code. Once you have that level of support
8+
it's time to move to Github.
9+
10+
For some types, however, we may want to stage introduction but make the type available to maintainers and
11+
early-adopters. To facilitate git submodule access to CETL and to avoid noise we use feature branches upstream to
12+
incubate such types. As such, we may request that your PR to `main` be redirected to a feature branch we setup in the
13+
form of `preview/{your incubating feature name}`.
14+
115
# Running CETLVaSt
216

317
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// @file
2+
/// Compile test that ensures CETL_H_ERASE works as intended.
3+
///
4+
/// @copyright
5+
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
6+
/// Copyright Amazon.com Inc. or its affiliates.
7+
/// SPDX-License-Identifier: MIT
8+
///
9+
10+
11+
#ifndef CETLVAST_COMPILETEST_PRECHECK
12+
#define CETL_H_ERASE
13+
#endif
14+
15+
// this should have an error macro that prevents compilation.
16+
#include "cetl/cetl.hpp"
17+
18+
int main()
19+
{
20+
return 0;
21+
}

include/cetl/cetl.hpp

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,59 @@
11
/// @file
22
/// CETL common header.
33
///
4+
/// @copyright
5+
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
6+
/// Copyright Amazon.com Inc. or its affiliates.
7+
/// SPDX-License-Identifier: MIT
8+
///
49
/// @note
510
/// Keep this very spare. CETL's desire is to adapt to future C++ standards
611
/// and too many CETL-specific definitions makes it difficult for users to switch off of CETL in the
712
/// future.
813
///
9-
/// @copyright
10-
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
11-
/// Copyright Amazon.com Inc. or its affiliates.
12-
/// SPDX-License-Identifier: MIT
14+
/// If `CETL_H_ERASE` is defined then all CETL types will exclude the `cetl/cetl.hpp` header which
15+
/// removes all common dependencies, other than C++ standard headers, from CETL. The types will not build due to
16+
/// missing macros but the user can re-define these based on subsequent compiler errors. This allows elision of
17+
/// cetl.hpp without modifying CETL source code. The CETL types are not guaranteed to work with cetl.hpp removed; you
18+
/// have been warned.
19+
///
20+
/// @warning
21+
/// polyfill headers cannot be used if CETL_H_ERASE is defined. Presumably, if you really want to minimize your
22+
/// dependencies, you would not be using the polyfill headers.
1323
///
1424

1525
#ifndef CETL_H_INCLUDED
1626
#define CETL_H_INCLUDED
1727

28+
#ifdef CETL_H_ERASE
29+
# error "CETL_H_ERASE was defined. This header should never be included when the build is trying to erase it!"
30+
#endif
31+
32+
/// @defgroup CETL_VERSION The semantic version number of the CETL library.
33+
/// These macros are an AUTOSAR-14 Rule A16-0-1 violation but we feel it necessary to provide them.
34+
/// @{
35+
36+
/// @def CETL_VERSION_PATCH
37+
/// CETL Patch version.
38+
/// Patch versions shall always be backwards compatible with the same major
39+
/// and minor version. A patch version number change will only occur if library source code is changed.
40+
/// Documentation or test suite changes will not require a change to `cetl/cetl.hpp` and will not bump
41+
/// the patch version.
42+
#define CETL_VERSION_PATCH 0
43+
44+
/// @def CETL_VERSION_MINOR
45+
/// CETL minor version.
46+
/// Minor versions shall only add to CETL or modify it in a backwards compatible way.
47+
#define CETL_VERSION_MINOR 0
48+
49+
/// @def CETL_VERSION_MAJOR
50+
/// CETL Major version.
51+
/// New major versions shall be rare. No overarching guarantees are made about compatibility
52+
/// between major versions.
53+
#define CETL_VERSION_MAJOR 0
54+
55+
/// @}
56+
1857
/// @def CETL_DEBUG_ASSERT
1958
/// When `CETL_ENABLE_DEBUG_ASSERT` is defined and not 0 then this is redirected to
2059
/// assert as included from `<cassert>`. Because assert does not support a failure message
@@ -36,13 +75,18 @@
3675
# define CETL_DEBUG_ASSERT(c, m) ((void) m)
3776
#endif // CETL_ENABLE_DEBUG_ASSERT
3877

39-
// For example: https://godbolt.org/z/Thsn8qf1a
40-
// We define these in a common header since we might encounter odd values on some compilers that we'll have to
41-
// provide special cases for.
42-
4378
/// @defgroup CETL_CPP_STANDARD Guaranteed CETL c++ standard numbers
4479
/// These macros are an AUTOSAR-14 Rule A16-0-1 violation but can be used to conditionally include headers which
45-
/// is compliant with A16-0-1.
80+
/// is compliant with A16-0-1. The values were obtained by observation of compiler output using
81+
/// [godbolt](https://godbolt.org/z/Thsn8qf1a) and as predicted by
82+
/// [cppreference.com](https://en.cppreference.com/w/cpp/preprocessor/replace#Predefined_macros).
83+
///
84+
/// @note
85+
/// Some CETL types don't use these values directly to reduce the number of explicit dependencies on cetl.hpp but by
86+
/// including `cetl/cetl.hpp` these types inherit the static assertions that the only valid values of `__cplusplus`
87+
/// found are one of the the list found in this group or a value greater than the target support `CETL_CPP_STANDARD_20`
88+
/// value.
89+
///
4690
/// @{
4791

4892
/// @def CETL_CPP_STANDARD_14
@@ -76,4 +120,14 @@
76120
#define CETL_CPP_STANDARD_20 202002L
77121

78122
/// @}
123+
124+
// Ensure base support.
125+
static_assert(__cplusplus >= CETL_CPP_STANDARD_14,
126+
"Unsupported language: ISO C14, C++14, or a newer version of either is required to use this type.");
127+
128+
// Detect weird versions
129+
static_assert(__cplusplus == CETL_CPP_STANDARD_14 || __cplusplus == CETL_CPP_STANDARD_17 ||
130+
__cplusplus >= CETL_CPP_STANDARD_20,
131+
"Unknown __cplusplus value found?");
132+
79133
#endif // CETL_H_INCLUDED

include/cetl/pf20/span.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#include <limits>
1717
#include <type_traits>
1818

19-
#include "cetl/cetl.hpp"
19+
#ifndef CETL_H_ERASE
20+
# include "cetl/cetl.hpp"
21+
#endif
2022

2123
namespace cetl
2224
{
@@ -329,7 +331,7 @@ class span
329331
/// If the span has a zero size or not.
330332
/// @return true if the span size is 0 where "size" is the same as span::extent
331333
/// for this specialization.
332-
#if (__cplusplus >= CETL_CPP_STANDARD_17)
334+
#if (__cplusplus >= 201703L)
333335
[[nodiscard]]
334336
#endif
335337
constexpr bool
@@ -687,7 +689,7 @@ class span<T, dynamic_extent>
687689
///
688690
/// Returns if the span has a zero size or not.
689691
/// @return true if the span size is 0.
690-
#if (__cplusplus >= CETL_CPP_STANDARD_17)
692+
#if (__cplusplus >= 201703L)
691693
[[nodiscard]]
692694
#endif
693695
constexpr bool

0 commit comments

Comments
 (0)