Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
cd ..
rm -rf __build

- name: Run modules tests wihtout 'import std;'
- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/libs/any
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
cd ..
rm -rf build_module

- name: Run modules tests wihtout 'import std;'
- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
Expand All @@ -243,8 +243,8 @@ jobs:
needs: posix
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
75 changes: 59 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,82 @@
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required( VERSION 3.5...3.31 )
project( boost_any VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
cmake_minimum_required(VERSION 3.21...4.2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codeowners what is the minimum version that must be supported?

import std; is usable starting with cmake v3.30 AFAIK

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to bump the minimum version so much. These CMake files are invoked from the Boost superproject, so bumping a minimum version in one affects every other library. I think 3.8 is okay.

Copy link
Author

@ClausKlein ClausKlein Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on every build host cmake v4.2 may be installed with pipx install cmake?

I want to have PROJECT_IS_TOP_LEVEL available with cmake version 3.21 anything older is not state of the art!


if (BOOST_USE_MODULES)
project(boost_any VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

if(PROJECT_IS_TOP_LEVEL)
find_package(Boost 1.90.0 CONFIG)
endif()

if(BOOST_USE_MODULES)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
endif()
add_library(boost_any)
target_sources(boost_any PUBLIC
FILE_SET modules_public TYPE CXX_MODULES FILES
${CMAKE_CURRENT_LIST_DIR}/modules/boost_any.cppm
target_sources(
boost_any
PUBLIC
FILE_SET modules_public
TYPE CXX_MODULES
FILES modules/boost_any.cppm
)

target_compile_features(boost_any PUBLIC cxx_std_20)
target_compile_definitions(boost_any PUBLIC BOOST_USE_MODULES)
if (CMAKE_CXX_COMPILER_IMPORT_STD)
if(${CMAKE_CXX_STANDARD} IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD)
set(CMAKE_CXX_MODULE_STD ON)
target_compile_definitions(boost_any PRIVATE BOOST_ANY_USE_STD_MODULE)
message(STATUS "Using `import std;`")
else()
message(STATUS "`import std;` is not available")
message(WARNING "`import std;` is not available")
endif()
set(__scope PUBLIC)
else()
set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ${PROJECT_IS_TOP_LEVEL})
add_library(boost_any INTERFACE)
set(__scope INTERFACE)
endif()

target_include_directories(boost_any ${__scope} include)
target_link_libraries( boost_any
${__scope}
Boost::config
Boost::throw_exception
Boost::type_index
)
if(CMAKE_VERSION VERSION_LESS 3.23)
target_include_directories(boost_any ${__scope} include)
else()
target_sources(
boost_any
${__scope}
FILE_SET headers_public
TYPE HEADERS
BASE_DIRS include
FILES
include/boost/any/bad_any_cast.hpp
include/boost/any/basic_any.hpp
include/boost/any/fwd.hpp
include/boost/any/unique_any.hpp
include/boost/any/detail/config.hpp
include/boost/any/detail/placeholder.hpp
)
if(NOT BOOST_USE_MODULES)
target_compile_features(boost_any ${__scope} cxx_std_17)
endif()
endif()

if(PROJECT_IS_TOP_LEVEL)
target_link_libraries(
boost_any
${__scope}
Boost::headers
)
else()
target_link_libraries(
boost_any
${__scope}
Boost::config
Boost::throw_exception
Boost::type_index
)
endif()

add_library( Boost::any ALIAS boost_any )
add_library(Boost::any ALIAS boost_any)

if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
3 changes: 3 additions & 0 deletions include/boost/any/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif

#include <type_traits>

#endif // #ifndef BOOST_ANY_INTERFACE_UNIT

/// \file boost/any/fwd.hpp
Expand Down
3 changes: 2 additions & 1 deletion modules/boost_any.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module;
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/throw_exception.hpp>
#include <boost/type_index.hpp>

import boost.type_index;

#ifdef BOOST_ANY_USE_STD_MODULE
import std;
Expand Down
44 changes: 42 additions & 2 deletions modules/usage_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,50 @@
// clang++ -std=c++20 -fmodule-file=type_index.pcm type_index.pcm usage_sample.cpp

//[any_module_example

#ifdef BOOST_ANY_USE_STD_MODULE
import std;
#else
# include <iostream>
# include <sstream>
# include <string>
#endif

import boost.any;

int main() {
boost::any a = 42;
namespace {

template <typename... Ts> auto any_to_string(const boost::any& a) -> std::string {
std::ostringstream oss;

auto try_cast = [&](auto* dummy) -> bool {
using T = std::decay_t<decltype(*dummy)>;
if (a.type() == typeid(T)) {
oss << boost::any_cast<T>(a);
return true;
}
return false;
};

// Expand over Ts...
bool const success = (try_cast((Ts*)nullptr) || ...);

if (!success) {
oss << "<unknown type: " << a.type().name() << ">";
}
return oss.str();
}

} // namespace

// Usage:
auto main() -> int {
boost::any const a = 42;
#ifdef BOOST_ANY_USE_STD_MODULE
std::println(stdout, "{}", any_to_string<int, double, std::string>(a));
#else
std::cout << any_to_string<int, double, std::string>(a) << '\n';
#endif
}
//]

10 changes: 5 additions & 5 deletions test/cmake_subdir_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# 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

cmake_minimum_required(VERSION 3.5...4.0)
cmake_minimum_required(VERSION 3.21...4.2)

project(any_subdir_test LANGUAGES CXX)

Expand All @@ -24,8 +24,8 @@ add_subdirectory(../../ boostorg/any)

enable_testing()

if (BOOST_USE_MODULES)
add_executable(boost_any_module_usage ../modules/usage_sample.cpp)
if(BOOST_USE_MODULES)
add_executable(boost_any_module_usage ../../modules/usage_sample.cpp)
target_link_libraries(boost_any_module_usage PRIVATE Boost::any)
add_test(NAME boost_any_module_usage COMMAND boost_any_module_usage)
endif()
Expand All @@ -47,10 +47,10 @@ list(APPEND RUN_TESTS_SOURCES
# any_test.cpp # Ambiguous with modules, because all the anys now available
)

foreach (testsourcefile ${RUN_TESTS_SOURCES})
foreach(testsourcefile ${RUN_TESTS_SOURCES})
get_filename_component(testname ${testsourcefile} NAME_WLE)
add_executable(${PROJECT_NAME}_${testname} ../${testsourcefile})
target_link_libraries(${PROJECT_NAME}_${testname} Boost::any)
target_link_libraries(${PROJECT_NAME}_${testname} Boost::any Boost::core)
add_test(NAME ${PROJECT_NAME}_${testname} COMMAND ${PROJECT_NAME}_${testname})
endforeach()

Loading