From aabf3afcb2c398dbb8c2902e60adbe29785ceb97 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Tue, 15 Apr 2025 18:41:23 +0100 Subject: [PATCH 01/11] Streamline and update CI --- .github/workflows/ci.yml | 149 ++------------------------------------- 1 file changed, 5 insertions(+), 144 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9469c1..7169173 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,12 +14,12 @@ on: release: types: [published, created, edited] jobs: - ubuntu-jammy: - runs-on: ubuntu-22.04 + ubuntu-24_04: + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - compiler: [ g++-11, g++-12, clang++-14 ] + compiler: [ g++-12, g++-13, clang++-15 clang++-16 ] standard: [ c++03, c++11, c++14, c++17, c++2a, gnu++03, gnu++11, gnu++14, gnu++17, gnu++2a ] steps: - uses: actions/checkout@v2 @@ -47,7 +47,7 @@ jobs: if: steps.retry1.outcome=='failure' run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - name: Install packages - run: sudo apt install g++-11 g++-12 clang-14 + run: sudo apt install g++-12 g++-13 clang-15 clang-16 - name: Checkout main boost run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root - name: Update tools/boostdep @@ -140,76 +140,13 @@ jobs: - name: Test run: ../../../b2 toolset=$TOOLSET working-directory: ../boost-root/libs/type_traits/test - ubuntu-focal: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - compiler: [ g++-9, g++-10, clang++-9, clang++-10 ] - standard: [ c++03, c++11, c++14, c++17, c++2a, gnu++03, gnu++11, gnu++14, gnu++17, gnu++2a ] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: '0' - - uses: mstachniuk/ci-skip@v1 - with: - commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[windows];[Windows];[WINDOWS];[apple];[Apple];[APPLE]' - commit-filter-separator: ';' - fail-fast: true - - name: Set TOOLSET - run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV - - name: Add repository - continue-on-error: true - id: addrepo - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Retry Add Repo - continue-on-error: true - id: retry1 - if: steps.addrepo.outcome=='failure' - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Retry Add Repo 2 - continue-on-error: true - id: retry2 - if: steps.retry1.outcome=='failure' - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Install packages - run: sudo apt install g++-9 g++-10 clang-9 clang-10 - - name: Checkout main boost - run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root - - name: Update tools/boostdep - run: git submodule update --init tools/boostdep - working-directory: ../boost-root - - name: Copy files - run: cp -r $GITHUB_WORKSPACE/* libs/type_traits - working-directory: ../boost-root - - name: Install deps - run: python tools/boostdep/depinst/depinst.py type_traits - working-directory: ../boost-root - - name: Bootstrap - run: ./bootstrap.sh - working-directory: ../boost-root - - name: Generate headers - run: ./b2 headers - working-directory: ../boost-root - - name: Generate user config - run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : -std=${{ matrix.standard }} ;" > ~/user-config.jam' - working-directory: ../boost-root - - name: Config info install - run: ../../../b2 config_info_travis_install toolset=$TOOLSET - working-directory: ../boost-root/libs/config/test - - name: Config info - run: ./config_info_travis - working-directory: ../boost-root/libs/config/test - - name: Test - run: ../../../b2 toolset=$TOOLSET - working-directory: ../boost-root/libs/type_traits/test macos: runs-on: macos-latest strategy: fail-fast: false matrix: toolset: [ clang ] - standard: [ "03", 11, 14, 17, 2a ] + standard: [ "03", 11, 14, 17, 20 ] steps: - uses: actions/checkout@v2 with: @@ -467,79 +404,3 @@ jobs: - name: Test run: ..\..\..\b2 --hash cxxstd=${{ matrix.standard }} toolset=msvc-14.2 define=CI_SUPPRESS_KNOWN_ISSUES cxxflags=-clr asynch-exceptions=on working-directory: ../boost-root/libs/type_traits/test - ubuntu-cuda: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - standard: [ 11, 14, 17 ] - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: '0' - - uses: Jimver/cuda-toolkit@v0.2.4 - - uses: mstachniuk/ci-skip@v1 - with: - commit-filter: '[skip ci];[ci skip];[CI SKIP];[SKIP CI];***CI SKIP***;***SKIP CI***;[windows];[Windows];[WINDOWS];[apple];[Apple];[APPLE]' - commit-filter-separator: ';' - fail-fast: true - - name: Add repository - continue-on-error: true - id: addrepo - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Retry Add Repo - continue-on-error: true - id: retry1 - if: steps.addrepo.outcome=='failure' - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Retry Add Repo 2 - continue-on-error: true - id: retry2 - if: steps.retry1.outcome=='failure' - run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - - name: Install packages - run: sudo apt install clang-10 - - name: Checkout main boost - run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root - - name: Update tools/boostdep - run: git submodule update --init tools/boostdep - working-directory: ../boost-root - - name: Copy files - run: cp -r $GITHUB_WORKSPACE/* libs/type_traits - working-directory: ../boost-root - - name: Install deps - run: python tools/boostdep/depinst/depinst.py type_traits - working-directory: ../boost-root - - name: Bootstrap - run: ./bootstrap.sh - working-directory: ../boost-root - - name: Generate headers - run: ./b2 headers - working-directory: ../boost-root - - name: nvcc version - run: nvcc --version - working-directory: ../boost-root/libs/config/test - - name: Testing nvcc - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cpp" && nvcc -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_VIA_STATIC_ASSERT $file.cpp || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing nvcc+clang - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cpp" && nvcc --compiler-bindir=clang++ -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_VIA_STATIC_ASSERT $file.cpp || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Create .cu files - run: for file in $(cat cuda/cuda_tests.txt); do cp $file.cpp $file.cu; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing nvcc on .cu files - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cu" && nvcc -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_VIA_STATIC_ASSERT $file.cu || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing nvcc+clang on .cu files - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cu" && nvcc --compiler-bindir=clang++ -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_VIA_STATIC_ASSERT $file.cu || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing clang on .cu files - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cu" && clang++ -nocudalib --no-cuda-version-check --cuda-gpu-arch=sm_75 -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_VIA_STATIC_ASSERT $file.cu || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing nvcc on .cu files - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cu" && nvcc -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_CUDA_DEVICE $file.cu || break -1; done - working-directory: ../boost-root/libs/type_traits/test - - name: Testing clang on .cu files - run: for file in $(cat cuda/cuda_tests.txt); do echo "testing $file.cu" && clang++ -nocudalib --no-cuda-version-check --cuda-gpu-arch=sm_75 -std=c++${{ matrix.standard }} -I../../.. -c -DTEST_CUDA_DEVICE $file.cu || break -1; done - working-directory: ../boost-root/libs/type_traits/test From f0bc869030c3b0c59db3fdd6ee406698cd7c5284 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 16 Apr 2025 17:10:37 +0100 Subject: [PATCH 02/11] Update clang versions. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7169173..a9befa7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - compiler: [ g++-12, g++-13, clang++-15 clang++-16 ] + compiler: [ g++-12, g++-13, clang++-15, clang++-16, clang++-17, clang++-18 ] standard: [ c++03, c++11, c++14, c++17, c++2a, gnu++03, gnu++11, gnu++14, gnu++17, gnu++2a ] steps: - uses: actions/checkout@v2 @@ -47,7 +47,7 @@ jobs: if: steps.retry1.outcome=='failure' run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" - name: Install packages - run: sudo apt install g++-12 g++-13 clang-15 clang-16 + run: sudo apt install g++-12 g++-13 clang-15 clang-16 clang-17 clang-18 - name: Checkout main boost run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root - name: Update tools/boostdep From 22fc23db2a46f614647b9df128dee63be2bade55 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 16 Apr 2025 18:06:07 +0100 Subject: [PATCH 03/11] Use depinst tool to handle dependencies in drone. --- .drone/boost.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/.drone/boost.sh b/.drone/boost.sh index 6acbbef..d304e13 100755 --- a/.drone/boost.sh +++ b/.drone/boost.sh @@ -19,23 +19,13 @@ cd .. git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root cd boost-root git submodule update --init tools/build +git submodule update --init libs/config +git submodule update --init libs/polygon git submodule update --init tools/boost_install git submodule update --init libs/headers -git submodule update --init libs/config -git submodule update --init libs/assert -git submodule update --init libs/bind -git submodule update --init libs/core -git submodule update --init libs/detail -git submodule update --init libs/function -git submodule update --init libs/integer -git submodule update --init libs/move -git submodule update --init libs/mpl -git submodule update --init libs/preprocessor -git submodule update --init libs/static_assert -git submodule update --init libs/throw_exception -git submodule update --init libs/type_index -git submodule update --init libs/utility +git submodule update --init tools/boostdep cp -r $TRAVIS_BUILD_DIR/* libs/type_traits +python tools/boostdep/depinst/depinst.py math ./bootstrap.sh ./b2 headers From 0098628ffc60ca2c41228c6b272f3f97934ca98b Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 16 Apr 2025 19:23:22 +0100 Subject: [PATCH 04/11] Correct drone script #2. --- .drone/boost.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.drone/boost.sh b/.drone/boost.sh index d304e13..b307d41 100755 --- a/.drone/boost.sh +++ b/.drone/boost.sh @@ -20,12 +20,11 @@ git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boos cd boost-root git submodule update --init tools/build git submodule update --init libs/config -git submodule update --init libs/polygon git submodule update --init tools/boost_install git submodule update --init libs/headers git submodule update --init tools/boostdep cp -r $TRAVIS_BUILD_DIR/* libs/type_traits -python tools/boostdep/depinst/depinst.py math +python tools/boostdep/depinst/depinst.py type_traits ./bootstrap.sh ./b2 headers From d3be907a0ec6f2811922cae0830bc3ba2556a73c Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 17 Apr 2025 16:50:47 +0100 Subject: [PATCH 05/11] Update linux image, use GCC-14 as well. --- .drone.star | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.star b/.drone.star index f77bc9d..681af54 100644 --- a/.drone.star +++ b/.drone.star @@ -22,7 +22,8 @@ def main(ctx): linux_cxx("TOOLSET=gcc COMPILER=g++-10 CXXSTD=03,11,14,17,20", "g++-10", packages="g++-10", image="cppalliance/droneubuntu2004:1", buildtype="boost", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-10', 'CXXSTD': '03,11,14,17,20'}, globalenv=globalenv), linux_cxx("TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a", "clang++-9", packages="clang-9", llvm_ver="9", buildtype="boost", image="cppalliance/droneubuntu2004:1", environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-9', 'CXXSTD': '03,11,14,17,2a'}, globalenv=globalenv), linux_cxx("TOOLSET=clang COMPILER=clang++-10 CXXSTD=03,11,14,17,20", "clang++-10", packages="clang-10", llvm_ver="10", buildtype="boost", image="cppalliance/droneubuntu2004:1", environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-10', 'CXXSTD': '03,11,14,17,20'}, globalenv=globalenv), - linux_cxx("Ubuntu g++-13", packages="g++-13", buildtype="boost", image="cppalliance/droneubuntu2304:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-13', 'CXXSTD': '14,17,20,23', }, globalenv=globalenv), + linux_cxx("Ubuntu g++-13", packages="g++-13", buildtype="boost", image="cppalliance/droneubuntu2404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-13', 'CXXSTD': '14,17,20,23', }, globalenv=globalenv), + linux_cxx("Ubuntu g++-14", packages="g++-14", buildtype="boost", image="cppalliance/droneubuntu2404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-14', 'CXXSTD': '14,17,20,23', }, globalenv=globalenv), osx_cxx("XCode-11.7 03,11,17,2a", "clang++", packages="", buildtype="boost", xcode_version="11.7", environment={'TOOLSET': 'clang', 'COMPILER': 'clang++', 'CXXSTD': '03,11,14,17,2a', }, globalenv=globalenv), osx_cxx("XCode-10.2 03,11,17,2a", "clang++", packages="", buildtype="boost", xcode_version="10.2", environment={'TOOLSET': 'clang', 'COMPILER': 'clang++', 'CXXSTD': '03,11,14,17,2a', }, globalenv=globalenv), ] From 14560070cab41ef6c76e94a85b80abb3a6bfdb82 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 21 May 2023 15:05:13 +0300 Subject: [PATCH 06/11] Make fallback is_complete implementation more robust. When all else fails, at least indicate the types that we always know to be incomplete: cv void and boundless arrays. Also cleanup formatting a bit. --- include/boost/type_traits/is_complete.hpp | 41 +++++++++++++++++------ test/is_complete_test.cpp | 16 +++++++-- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/include/boost/type_traits/is_complete.hpp b/include/boost/type_traits/is_complete.hpp index 08f0e62..428edf1 100644 --- a/include/boost/type_traits/is_complete.hpp +++ b/include/boost/type_traits/is_complete.hpp @@ -27,11 +27,10 @@ * DO NOT MAKE GENERAL USE OF THIS TRAIT, AS THE COMPLETENESS OF A TYPE * VARIES ACROSS TRANSLATION UNITS AS WELL AS WITHIN A SINGLE UNIT. * -*/ + */ namespace boost { - // // We will undef this if the trait isn't fully functional: // @@ -39,7 +38,7 @@ namespace boost { #if !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40600) - namespace detail{ + namespace detail { template struct ok_tag { double d; char c[N]; }; @@ -48,15 +47,15 @@ namespace boost { ok_tag check_is_complete(int); template char check_is_complete(...); - } + + } // namespace detail template struct is_complete : public integral_constant::type>::value || (sizeof(boost::detail::check_is_complete(0)) != sizeof(char))> {}; #elif !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) - namespace detail - { + namespace detail { template struct is_complete_imp @@ -70,7 +69,7 @@ namespace boost { static const bool value = sizeof(check(0)) == sizeof(type_traits::yes_type); }; -} // namespace detail + } // namespace detail template @@ -78,11 +77,33 @@ namespace boost { {}; template struct is_complete : boost::is_complete {}; - + #else - template struct is_complete - : public boost::integral_constant {}; + namespace detail { + + template + struct is_complete_impl : public boost::true_type {}; + + template < > + struct is_complete_impl : public boost::false_type {}; + + template + struct is_complete_impl : public boost::false_type {}; + + template + struct is_complete_impl : public is_complete_impl::type {}; + + } // namespace detail + + template + struct is_complete : public detail::is_complete_impl::type {}; + template + struct is_complete : public detail::is_complete_impl::type {}; + template + struct is_complete : public detail::is_complete_impl::type {}; + template + struct is_complete : public detail::is_complete_impl::type {}; #undef BOOST_TT_HAS_WORKING_IS_COMPLETE diff --git a/test/is_complete_test.cpp b/test/is_complete_test.cpp index 075e70d..74d7a3d 100644 --- a/test/is_complete_test.cpp +++ b/test/is_complete_test.cpp @@ -14,6 +14,15 @@ TT_TEST_BEGIN(is_complete) +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); + BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); @@ -31,9 +40,11 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); -#ifdef BOOST_TT_HAS_WORKING_IS_COMPLETE + BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); -#endif +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); @@ -46,6 +57,7 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); #ifdef BOOST_TT_HAS_WORKING_IS_COMPLETE BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, false); #endif +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_complete::value, true); From 0422aebeb80deac7a69757faf121f35b9beba5cd Mon Sep 17 00:00:00 2001 From: Adder Date: Tue, 13 Jun 2023 23:29:56 +0300 Subject: [PATCH 07/11] `integral_constant`: MPL interop: Avoid `reinterpret_cast`. Conversion between pointers to unrelated types `Source` and `Target` can be done with two `static_cast`'s ("upcast" to pointer to cv-void followed by "downcast") => (IMO) it should be done with `static_cast` (in order not to give the impression that `reinterpret_cast` really is needed): `T *ptr_target = static_cast (static_cast (ptr_source));` (Maybe that was the original intent of introducing `pdata`.) --- include/boost/type_traits/integral_constant.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/type_traits/integral_constant.hpp b/include/boost/type_traits/integral_constant.hpp index 2592bcb..47699be 100644 --- a/include/boost/type_traits/integral_constant.hpp +++ b/include/boost/type_traits/integral_constant.hpp @@ -61,7 +61,7 @@ namespace boost{ { static const char data[sizeof(long)] = { 0 }; static const void* pdata = data; - return *(reinterpret_cast*>(pdata)); + return *static_cast*>(pdata); } BOOST_CONSTEXPR operator T()const { return val; } }; @@ -81,7 +81,7 @@ namespace boost{ { static const char data[sizeof(long)] = { 0 }; static const void* pdata = data; - return *(reinterpret_cast*>(pdata)); + return *static_cast*>(pdata); } BOOST_CONSTEXPR operator bool()const { return val; } }; From ff0ae13c648bd17ba436717933f2a38d8243738d Mon Sep 17 00:00:00 2001 From: Adder Date: Mon, 6 Jan 2025 00:24:20 +0200 Subject: [PATCH 08/11] `integral_constant`: MPL interop: Avoid one function-local `static` object. If the compiler does not optimize away the `pdata` function-local `static` object, it ends up occupying space in the data section and it is going to need a corresponding relocation entry (just in case the module is not loaded at the desired address, as is the case with ASLR in Windows Vista and later and in modern versions of Linux). I admit that, for the current code, both MSVC and GCC manage to optimize away `pdata` even if it is `static`. But Boost should be an example of good coding which can be applied even to more complicated source code, e.g. to source code which calls `opaque_function (&pdata)` (in which case, if `pdata` is static, both MSVC and GCC do emit an extra relocation). And for other more complex cases, a function-local static-storage-duration object costs even more (as compared to a function-local automatic-storage-duration object given C++11 rules for "thread-safe" initialization of function-local `static`s. And I wish to re-iterate that, in my opinion, a good way to cast a pointer-to-one-type to a pointer-to-an-unrelated-type is not by `reinterpret_cast` (which by the way makes `pdata` not needed any more), but by using pointer to (possibly cv-qualified) `void` as an intermediary pointer type: ``` return static_cast (static_cast (pointer_to_source)) ``` or: ``` const void *const intermediary (pointer_to_source); // Not `static` for the general case. return static_cast (intermediary); ``` Therefore, if the authors kindly agree, we can make this code an example for this style. --- include/boost/type_traits/integral_constant.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/type_traits/integral_constant.hpp b/include/boost/type_traits/integral_constant.hpp index 47699be..9a65df3 100644 --- a/include/boost/type_traits/integral_constant.hpp +++ b/include/boost/type_traits/integral_constant.hpp @@ -60,7 +60,7 @@ namespace boost{ operator const mpl::integral_c& ()const { static const char data[sizeof(long)] = { 0 }; - static const void* pdata = data; + const void* const pdata = data; return *static_cast*>(pdata); } BOOST_CONSTEXPR operator T()const { return val; } @@ -80,7 +80,7 @@ namespace boost{ operator const mpl::bool_& ()const { static const char data[sizeof(long)] = { 0 }; - static const void* pdata = data; + const void* const pdata = data; return *static_cast*>(pdata); } BOOST_CONSTEXPR operator bool()const { return val; } From f31a9da4d803efe0788b7fd2428f5787ad59edea Mon Sep 17 00:00:00 2001 From: Adder Date: Tue, 7 Jan 2025 00:19:34 +0200 Subject: [PATCH 09/11] `integral_constant`: As per `std`: Mark `operator T` as `noexcept`. In the C++ Standard Library, `std::integral_constant` has its `operator T` marked as `noexcept`: https://timsong-cpp.github.io/cppwp/meta.help We hereby do the same for the Boost version. --- include/boost/type_traits/integral_constant.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/type_traits/integral_constant.hpp b/include/boost/type_traits/integral_constant.hpp index 9a65df3..284ed02 100644 --- a/include/boost/type_traits/integral_constant.hpp +++ b/include/boost/type_traits/integral_constant.hpp @@ -63,7 +63,7 @@ namespace boost{ const void* const pdata = data; return *static_cast*>(pdata); } - BOOST_CONSTEXPR operator T()const { return val; } + BOOST_CONSTEXPR operator T()const BOOST_NOEXCEPT { return val; } }; template @@ -83,7 +83,7 @@ namespace boost{ const void* const pdata = data; return *static_cast*>(pdata); } - BOOST_CONSTEXPR operator bool()const { return val; } + BOOST_CONSTEXPR operator bool()const BOOST_NOEXCEPT { return val; } }; template From 4126ca650cb318f034420fac69b9101e16bc13c1 Mon Sep 17 00:00:00 2001 From: Adder Date: Tue, 7 Jan 2025 00:43:06 +0200 Subject: [PATCH 10/11] `integral_constant`: As per `std`: Add `operator()`. In the C++ Standard Library, `std::integral_constant` has `operator()`: https://timsong-cpp.github.io/cppwp/meta.help We hereby add `operator()` for the Boost version. --- .../boost/type_traits/integral_constant.hpp | 2 ++ test/integral_constant_test.cpp | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 test/integral_constant_test.cpp diff --git a/include/boost/type_traits/integral_constant.hpp b/include/boost/type_traits/integral_constant.hpp index 284ed02..7424c86 100644 --- a/include/boost/type_traits/integral_constant.hpp +++ b/include/boost/type_traits/integral_constant.hpp @@ -64,6 +64,7 @@ namespace boost{ return *static_cast*>(pdata); } BOOST_CONSTEXPR operator T()const BOOST_NOEXCEPT { return val; } + BOOST_CONSTEXPR T operator()()const BOOST_NOEXCEPT { return val; } }; template @@ -84,6 +85,7 @@ namespace boost{ return *static_cast*>(pdata); } BOOST_CONSTEXPR operator bool()const BOOST_NOEXCEPT { return val; } + BOOST_CONSTEXPR bool operator()()const BOOST_NOEXCEPT { return val; } }; template diff --git a/test/integral_constant_test.cpp b/test/integral_constant_test.cpp new file mode 100755 index 0000000..6938d5d --- /dev/null +++ b/test/integral_constant_test.cpp @@ -0,0 +1,28 @@ +// Copyright 2025 DoctorNoobingstoneIPresume +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +int main () +{ + // [2025-01-07] Adapted from example in https://en.cppreference.com/w/cpp/types/integral_constant ... + + using two_t = boost::integral_constant ; + using four_t = boost::integral_constant ; + + BOOST_STATIC_ASSERT ((! boost::is_same ::value)); + BOOST_STATIC_ASSERT ((two_t::value * 2 == four_t::value)); + BOOST_STATIC_ASSERT ((two_t () << 1 == four_t ())); + BOOST_STATIC_ASSERT ((two_t () () << 1 == four_t () ())); + + enum class E {e0, e1}; + using c0 = boost::integral_constant ; + using c1 = boost::integral_constant ; + BOOST_STATIC_ASSERT ((c0::value != E::e1)); + BOOST_STATIC_ASSERT ((c0 () == E::e0)); + BOOST_STATIC_ASSERT ((boost::is_same ::value)); +} From 5329d1d4978d737eb0b49e114156b262a53ca6f2 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 21 Apr 2025 13:40:42 +0100 Subject: [PATCH 11/11] Disable constexpr test in C++03. --- test/integral_constant_test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/integral_constant_test.cpp b/test/integral_constant_test.cpp index 6938d5d..fc4cb35 100755 --- a/test/integral_constant_test.cpp +++ b/test/integral_constant_test.cpp @@ -11,6 +11,8 @@ int main () { // [2025-01-07] Adapted from example in https://en.cppreference.com/w/cpp/types/integral_constant ... +#ifndef BOOST_NO_CXX11_CONSTEXPR + using two_t = boost::integral_constant ; using four_t = boost::integral_constant ; @@ -25,4 +27,5 @@ int main () BOOST_STATIC_ASSERT ((c0::value != E::e1)); BOOST_STATIC_ASSERT ((c0 () == E::e0)); BOOST_STATIC_ASSERT ((boost::is_same ::value)); +#endif }