mirror of
https://github.com/boostorg/conversion.git
synced 2026-08-07 14:04:20 +02:00
Compare commits
9 Commits
boost-1.87.0
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 827dd94c68 | |||
| 782e083f61 | |||
| 1e6424563d | |||
| 6632ca9309 | |||
| b74a4c34cb | |||
| 452adac97f | |||
| 5f82d5aa7d | |||
| 9d64c899df | |||
| 35a71f0701 |
@@ -0,0 +1,11 @@
|
|||||||
|
# To get started with Dependabot version updates, you'll need to specify which
|
||||||
|
# package ecosystems to update and where the package manifests are located.
|
||||||
|
# Please see the documentation for all configuration options:
|
||||||
|
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions" # See documentation for possible values
|
||||||
|
directory: "/" # Location of package manifests
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
@@ -17,6 +17,9 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
|
- toolset: gcc-14 # Do not remove! It is the only toolset that tests CMake tests down below
|
||||||
|
cxxstd: "03,11,14,17,20"
|
||||||
|
os: ubuntu-24.04
|
||||||
- toolset: gcc-12
|
- toolset: gcc-12
|
||||||
cxxstd: "03,11,14,17,2a"
|
cxxstd: "03,11,14,17,2a"
|
||||||
os: ubuntu-22.04
|
os: ubuntu-22.04
|
||||||
@@ -31,7 +34,7 @@ jobs:
|
|||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Install packages
|
- name: Install packages
|
||||||
if: matrix.install
|
if: matrix.install
|
||||||
@@ -59,8 +62,19 @@ jobs:
|
|||||||
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
|
||||||
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
|
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
|
||||||
./bootstrap.sh
|
./bootstrap.sh
|
||||||
./b2 -d0 headers
|
./b2 -j4 variant=debug tools/inspect
|
||||||
./b2 -j4 variant=debug tools/inspect/build
|
|
||||||
|
- name: Run CMake tests
|
||||||
|
if: ${{matrix.toolset == 'gcc-14'}}
|
||||||
|
run: |
|
||||||
|
cd ../boost-root/
|
||||||
|
mkdir __build
|
||||||
|
cd __build
|
||||||
|
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=conversion -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_C_COMPILER=gcc-14 ..
|
||||||
|
cmake --build . --target tests
|
||||||
|
ctest --output-on-failure --no-tests=error
|
||||||
|
cd ..
|
||||||
|
rm -rf __build
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
@@ -101,19 +115,19 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- toolset: msvc-14.2
|
- toolset: msvc-14.3
|
||||||
cxxstd: "14,17,latest"
|
cxxstd: "14,17,latest"
|
||||||
addrmd: 32,64
|
addrmd: 32,64
|
||||||
os: windows-2019
|
os: windows-2025
|
||||||
- toolset: gcc
|
- toolset: gcc
|
||||||
cxxstd: "03,11,14,17,2a"
|
cxxstd: "03,11,14,17,2a"
|
||||||
addrmd: 64
|
addrmd: 64
|
||||||
os: windows-2019
|
os: windows-2025
|
||||||
|
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Setup Boost
|
- name: Setup Boost
|
||||||
shell: cmd
|
shell: cmd
|
||||||
@@ -135,7 +149,21 @@ jobs:
|
|||||||
git submodule update --init tools/boostdep
|
git submodule update --init tools/boostdep
|
||||||
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
|
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
|
||||||
cmd /c bootstrap
|
cmd /c bootstrap
|
||||||
b2 -d0 headers
|
|
||||||
|
- name: Run CMake tests
|
||||||
|
if: ${{matrix.toolset == 'msvc-14.3'}}
|
||||||
|
shell: cmd
|
||||||
|
run: |
|
||||||
|
choco install --no-progress ninja
|
||||||
|
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
|
||||||
|
cd ../boost-root/
|
||||||
|
mkdir __build
|
||||||
|
cd __build
|
||||||
|
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=conversion ..
|
||||||
|
cmake --build . --target tests --config Debug
|
||||||
|
ctest --output-on-failure --no-tests=error -C Debug
|
||||||
|
cd ..
|
||||||
|
rm -rf __build
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
shell: cmd
|
shell: cmd
|
||||||
|
|||||||
+5
-2
@@ -2,7 +2,7 @@
|
|||||||
# Distributed under the Boost Software License, Version 1.0.
|
# 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
|
# 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.20 )
|
cmake_minimum_required( VERSION 3.5...4.20 )
|
||||||
project( boost_conversion VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
|
project( boost_conversion VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX )
|
||||||
|
|
||||||
add_library( boost_conversion INTERFACE )
|
add_library( boost_conversion INTERFACE )
|
||||||
@@ -14,6 +14,9 @@ target_link_libraries( boost_conversion
|
|||||||
INTERFACE
|
INTERFACE
|
||||||
Boost::assert
|
Boost::assert
|
||||||
Boost::config
|
Boost::config
|
||||||
Boost::smart_ptr
|
|
||||||
Boost::throw_exception
|
Boost::throw_exception
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ Boost.Conversion is one of the [Boost C++ Libraries](https://github.com/boostorg
|
|||||||
|
|
||||||
@ | Build | Tests coverage | More info
|
@ | Build | Tests coverage | More info
|
||||||
----------------|-------------- | -------------- |-----------
|
----------------|-------------- | -------------- |-----------
|
||||||
Develop branch: | [](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [](https://ci.appveyor.com/project/apolukhin/conversion/branch/develop) | [](https://coveralls.io/github/boostorg/conversion?branch=develop) | [details...](https://www.boost.org/development/tests/develop/developer/conversion.html)
|
Develop branch: | [](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [](https://ci.appveyor.com/project/apolukhin/conversion/branch/develop) | [](https://coveralls.io/github/boostorg/conversion?branch=develop) | [details...](https://regression.boost.io/develop/developer/conversion.html)
|
||||||
Master branch: | [](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [](https://ci.appveyor.com/project/apolukhin/conversion/branch/master) | [](https://coveralls.io/github/boostorg/conversion?branch=master) | [details...](https://www.boost.org/development/tests/master/developer/conversion.html)
|
Master branch: | [](https://github.com/boostorg/conversion/actions/workflows/ci.yml) [](https://ci.appveyor.com/project/apolukhin/conversion/branch/master) | [](https://coveralls.io/github/boostorg/conversion?branch=master) | [details...](https://regression.boost.io/master/developer/conversion.html)
|
||||||
|
|
||||||
[Latest developer documentation](https://www.boost.org/doc/libs/develop/doc/html/conversion.html)
|
[Latest developer documentation](https://www.boost.org/doc/libs/develop/doc/html/conversion.html)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ require-b2 5.2 ;
|
|||||||
constant boost_dependencies :
|
constant boost_dependencies :
|
||||||
/boost/assert//boost_assert
|
/boost/assert//boost_assert
|
||||||
/boost/config//boost_config
|
/boost/config//boost_config
|
||||||
/boost/smart_ptr//boost_smart_ptr
|
|
||||||
/boost/throw_exception//boost_throw_exception ;
|
/boost/throw_exception//boost_throw_exception ;
|
||||||
|
|
||||||
project /boost/conversion
|
project /boost/conversion
|
||||||
|
|||||||
+9
-9
@@ -1,6 +1,6 @@
|
|||||||
[/
|
[/
|
||||||
Copyright 2016 Mikhail Maximov.
|
Copyright 2016 Mikhail Maximov.
|
||||||
Copyright Antony Polukhin, 2020-2024.
|
Copyright Antony Polukhin, 2020-2026.
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
[id conversion]
|
[id conversion]
|
||||||
[version 1.7]
|
[version 1.7]
|
||||||
[authors [Stroustrup, Bjarne], [Abrahams, Dave], [Rasin, Boris], [Polukhin, Antony]]
|
[authors [Stroustrup, Bjarne], [Abrahams, Dave], [Rasin, Boris], [Polukhin, Antony]]
|
||||||
[copyright 2001 Beman Dawes, 2014-2024 Antony Polukhin]
|
[copyright 2001 Beman Dawes, 2014-2026 Antony Polukhin]
|
||||||
[license
|
[license
|
||||||
Distributed under the Boost Software License, Version 1.0.
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
(See accompanying file LICENSE_1_0.txt or copy at
|
(See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -150,10 +150,10 @@ This includes C++ built-in pointers, `std::shared_ptr`,
|
|||||||
class Banana : public Fruit {};
|
class Banana : public Fruit {};
|
||||||
|
|
||||||
// Use one of these:
|
// Use one of these:
|
||||||
typedef Fruit* FruitPtr;
|
using FruitPtr = Fruit*;
|
||||||
typedef std::shared_ptr<Fruit> FruitPtr;
|
using FruitPtr = std::shared_ptr<Fruit>;
|
||||||
typedef boost::shared_ptr<Fruit> FruitPtr;
|
using FruitPtr = boost::shared_ptr<Fruit>;
|
||||||
typedef boost::intrusive_ptr<Fruit> FruitPtr;
|
using FruitPtr = boost::intrusive_ptr<Fruit>;
|
||||||
|
|
||||||
void f(FruitPtr fruit) {
|
void f(FruitPtr fruit) {
|
||||||
// ... logic which leads us to believe it is a banana
|
// ... logic which leads us to believe it is a banana
|
||||||
@@ -173,17 +173,17 @@ This includes C++ built-in pointers, `std::shared_ptr`,
|
|||||||
// Throws: std::bad_cast if ( dynamic_cast<Derived>(x) == 0 )
|
// Throws: std::bad_cast if ( dynamic_cast<Derived>(x) == 0 )
|
||||||
// Returns: dynamic_cast<Derived>(x)
|
// Returns: dynamic_cast<Derived>(x)
|
||||||
template <class Derived, class Base>
|
template <class Derived, class Base>
|
||||||
inline Derived polymorphic_cast(Base* x);
|
constexpr Derived polymorphic_cast(Base* x);
|
||||||
|
|
||||||
// Effects: assert( dynamic_cast<Derived>(x) == x );
|
// Effects: assert( dynamic_cast<Derived>(x) == x );
|
||||||
// Returns: static_cast<Derived>(x)
|
// Returns: static_cast<Derived>(x)
|
||||||
template <class Derived, class Base>
|
template <class Derived, class Base>
|
||||||
inline Derived polymorphic_downcast(Base* x);
|
constexpr Derived polymorphic_downcast(Base* x);
|
||||||
|
|
||||||
// Effects: assert( dynamic_cast<Derived>(&x) == &x );
|
// Effects: assert( dynamic_cast<Derived>(&x) == &x );
|
||||||
// Returns: static_cast<Derived>(x)
|
// Returns: static_cast<Derived>(x)
|
||||||
template <class Derived, class Base>
|
template <class Derived, class Base>
|
||||||
inline Derived polymorphic_downcast(Base& x);
|
constexpr Derived polymorphic_downcast(Base& x);
|
||||||
|
|
||||||
// Throws: std::bad_cast if ( dynamic_pointer_cast<Derived>(x) == 0 )
|
// Throws: std::bad_cast if ( dynamic_pointer_cast<Derived>(x) == 0 )
|
||||||
// Returns: dynamic_pointer_cast<Derived>(x)
|
// Returns: dynamic_pointer_cast<Derived>(x)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace detail {
|
|||||||
|
|
||||||
template<class T> struct icast_identity
|
template<class T> struct icast_identity
|
||||||
{
|
{
|
||||||
typedef T type;
|
using type = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
// 08 Nov 14 Add polymorphic_pointer_downcast (Boris Rasin)
|
// 08 Nov 14 Add polymorphic_pointer_downcast (Boris Rasin)
|
||||||
// 09 Jun 14 "cast.hpp" was renamed to "polymorphic_cast.hpp" and
|
// 09 Jun 14 "cast.hpp" was renamed to "polymorphic_cast.hpp" and
|
||||||
// inclusion of numeric_cast was removed (Antony Polukhin)
|
// inclusion of numeric_cast was removed (Antony Polukhin)
|
||||||
// 23 Jun 05 numeric_cast removed and redirected to the new verion (Fernando Cacciola)
|
// 23 Jun 05 numeric_cast removed and redirected to the new version (Fernando Cacciola)
|
||||||
// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included
|
// 02 Apr 01 Removed BOOST_NO_LIMITS workarounds and included
|
||||||
// <boost/limits.hpp> instead (the workaround did not
|
// <boost/limits.hpp> instead (the workaround did not
|
||||||
// actually compile when BOOST_NO_LIMITS was defined in
|
// actually compile when BOOST_NO_LIMITS was defined in
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams)
|
// 19 Oct 00 Fix numeric_cast for floating-point types (Dave Abrahams)
|
||||||
// 15 Jul 00 Suppress numeric_cast warnings for GCC, Borland and MSVC
|
// 15 Jul 00 Suppress numeric_cast warnings for GCC, Borland and MSVC
|
||||||
// (Dave Abrahams)
|
// (Dave Abrahams)
|
||||||
// 30 Jun 00 More MSVC6 wordarounds. See comments below. (Dave Abrahams)
|
// 30 Jun 00 More MSVC6 workarounds. See comments below. (Dave Abrahams)
|
||||||
// 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes)
|
// 28 Jun 00 Removed implicit_cast<>. See comment below. (Beman Dawes)
|
||||||
// 27 Jun 00 More MSVC6 workarounds
|
// 27 Jun 00 More MSVC6 workarounds
|
||||||
// 15 Jun 00 Add workarounds for MSVC6
|
// 15 Jun 00 Add workarounds for MSVC6
|
||||||
@@ -62,6 +62,12 @@
|
|||||||
# include <typeinfo>
|
# include <typeinfo>
|
||||||
# include <type_traits>
|
# include <type_traits>
|
||||||
|
|
||||||
|
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||||
|
#define BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST constexpr
|
||||||
|
#else
|
||||||
|
#define BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST inline
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
// See the documentation for descriptions of how to choose between
|
// See the documentation for descriptions of how to choose between
|
||||||
@@ -74,7 +80,7 @@ namespace boost
|
|||||||
// section 15.8 exercise 1, page 425.
|
// section 15.8 exercise 1, page 425.
|
||||||
|
|
||||||
template <class Target, class Source>
|
template <class Target, class Source>
|
||||||
inline Target polymorphic_cast(Source* x)
|
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST Target polymorphic_cast(Source* x)
|
||||||
{
|
{
|
||||||
Target tmp = dynamic_cast<Target>(x);
|
Target tmp = dynamic_cast<Target>(x);
|
||||||
if ( tmp == 0 ) boost::throw_exception( std::bad_cast() );
|
if ( tmp == 0 ) boost::throw_exception( std::bad_cast() );
|
||||||
@@ -93,7 +99,7 @@ namespace boost
|
|||||||
// Contributed by Dave Abrahams
|
// Contributed by Dave Abrahams
|
||||||
|
|
||||||
template <class Target, class Source>
|
template <class Target, class Source>
|
||||||
inline Target polymorphic_downcast(Source* x)
|
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST Target polymorphic_downcast(Source* x)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
|
BOOST_ASSERT( dynamic_cast<Target>(x) == x ); // detect logic error
|
||||||
return static_cast<Target>(x);
|
return static_cast<Target>(x);
|
||||||
@@ -109,11 +115,11 @@ namespace boost
|
|||||||
// Contributed by Julien Delacroix
|
// Contributed by Julien Delacroix
|
||||||
|
|
||||||
template <class Target, class Source>
|
template <class Target, class Source>
|
||||||
inline typename std::enable_if<
|
BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST typename std::enable_if<
|
||||||
std::is_reference<Target>::value, Target
|
std::is_reference<Target>::value, Target
|
||||||
>::type polymorphic_downcast(Source& x)
|
>::type polymorphic_downcast(Source& x)
|
||||||
{
|
{
|
||||||
typedef typename std::remove_reference<Target>::type* target_pointer_type;
|
using target_pointer_type = typename std::remove_reference<Target>::type*;
|
||||||
return *boost::polymorphic_downcast<target_pointer_type>(
|
return *boost::polymorphic_downcast<target_pointer_type>(
|
||||||
std::addressof(x)
|
std::addressof(x)
|
||||||
);
|
);
|
||||||
@@ -121,4 +127,6 @@ namespace boost
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
#undef BOOST_CONVERSION_IMPL_CONSTEXPR_DYN_CAST
|
||||||
|
|
||||||
#endif // BOOST_POLYMORPHIC_CAST_HPP
|
#endif // BOOST_POLYMORPHIC_CAST_HPP
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// boost polymorphic_pointer_cast.hpp header file ----------------------------------------------//
|
// boost polymorphic_pointer_cast.hpp header file ----------------------------------------------//
|
||||||
// (C) Copyright Boris Rasin, 2014-2021.
|
// (C) Copyright Boris Rasin, 2014-2021.
|
||||||
// (C) Copyright Antony Polukhin, 2014-2024.
|
// (C) Copyright Antony Polukhin, 2014-2026.
|
||||||
// Distributed under the Boost
|
// Distributed under the Boost
|
||||||
// Software License, Version 1.0. (See accompanying file
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
Copyright (c) 2016 Mikhail Maximov
|
Copyright (c) 2016 Mikhail Maximov
|
||||||
vigorous.activity at gmail dot com
|
vigorous.activity at gmail dot com
|
||||||
|
|
||||||
Copyright (c) Antony Polukhin, 2021-2024
|
Copyright (c) Antony Polukhin, 2021-2026
|
||||||
|
|
||||||
Distributed under the Boost Software License,
|
Distributed under the Boost Software License,
|
||||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# Copyright (c) 2016-2026 Antony Polukhin
|
||||||
|
# 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(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
|
||||||
|
|
||||||
|
if(NOT HAVE_BOOST_TEST)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(BOOST_TEST_LINK_LIBRARIES Boost::conversion Boost::core)
|
||||||
|
|
||||||
|
boost_test(TYPE run SOURCES cast_test.cpp)
|
||||||
|
boost_test(TYPE run SOURCES implicit_cast.cpp)
|
||||||
|
boost_test(TYPE compile-fail SOURCES implicit_cast_fail.cpp)
|
||||||
|
boost_test(TYPE compile-fail SOURCES implicit_cast_fail2.cpp)
|
||||||
|
boost_test(TYPE run SOURCES polymorphic_cast_test.cpp LINK_LIBRARIES Boost::smart_ptr)
|
||||||
+1
-1
@@ -26,6 +26,6 @@ test-suite conversion
|
|||||||
: [ run implicit_cast.cpp ]
|
: [ run implicit_cast.cpp ]
|
||||||
[ compile-fail implicit_cast_fail.cpp ]
|
[ compile-fail implicit_cast_fail.cpp ]
|
||||||
[ run cast_test.cpp ]
|
[ run cast_test.cpp ]
|
||||||
[ run polymorphic_cast_test.cpp ]
|
[ run polymorphic_cast_test.cpp : : : <library>/boost/smart_ptr//boost_smart_ptr ]
|
||||||
[ compile-fail implicit_cast_fail2.cpp ]
|
[ compile-fail implicit_cast_fail2.cpp ]
|
||||||
;
|
;
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
# subject to the Boost Software License, Version 1.0. (See accompanying
|
# subject to 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)
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
#
|
#
|
||||||
# Copyright Antony Polukhin, 2016-2024.
|
# Copyright Antony Polukhin, 2016-2025.
|
||||||
|
|
||||||
#
|
#
|
||||||
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
|
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
|
||||||
|
|||||||
@@ -38,6 +38,48 @@ namespace
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr bool compile_time_polymorphic_cast_check() {
|
||||||
|
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||||
|
Derived derived;
|
||||||
|
Base* base = &derived;
|
||||||
|
return polymorphic_cast<Derived*>(base) != nullptr;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
compile_time_polymorphic_cast_check(),
|
||||||
|
"polymorphic_cast does not work at compile time"
|
||||||
|
);
|
||||||
|
|
||||||
|
constexpr bool compile_time_polymorphic_downcast_check() {
|
||||||
|
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||||
|
Derived derived;
|
||||||
|
Base* base = &derived;
|
||||||
|
return polymorphic_downcast<Derived*>(base) != nullptr;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
compile_time_polymorphic_downcast_check(),
|
||||||
|
"polymorphic_downcast does not work at compile time"
|
||||||
|
);
|
||||||
|
|
||||||
|
constexpr bool compile_time_polymorphic_downcast2_check() {
|
||||||
|
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
|
||||||
|
Derived derived;
|
||||||
|
Base& base = derived;
|
||||||
|
Derived& derived_again = polymorphic_downcast<Derived&>(base);
|
||||||
|
(void)derived_again;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
compile_time_polymorphic_downcast2_check(),
|
||||||
|
"polymorphic_downcast does not work at compile time"
|
||||||
|
);
|
||||||
|
|
||||||
int main( int argc, char * argv[] )
|
int main( int argc, char * argv[] )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
#include <boost/implicit_cast.hpp>
|
#include <boost/implicit_cast.hpp>
|
||||||
#include <boost/detail/lightweight_test.hpp>
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <boost/type.hpp>
|
#include <boost/type.hpp>
|
||||||
|
|
||||||
using boost::implicit_cast;
|
using boost::implicit_cast;
|
||||||
using boost::type;
|
using boost::type;
|
||||||
|
|
||||||
@@ -18,8 +19,8 @@ struct foo
|
|||||||
operator long() const { return 0; }
|
operator long() const { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef type<long> long_type;
|
using long_type = type<long>;
|
||||||
typedef type<foo> foo_type;
|
using foo_type = type<foo>;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user