Skip to content

Commit

Permalink
Use Standard Library type traits
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Dec 17, 2024
1 parent 06bc4c8 commit d80110d
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 100 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ target_link_libraries(boost_dll
Boost::config
Boost::core
Boost::filesystem
Boost::function
Boost::move
Boost::predef
Boost::smart_ptr
Boost::spirit
Boost::system
Boost::throw_exception
Boost::type_index
Boost::type_traits
Boost::winapi
)

Expand Down
1 change: 0 additions & 1 deletion build.jam
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ constant boost_dependencies :
/boost/system//boost_system
/boost/throw_exception//boost_throw_exception
/boost/type_index//boost_type_index
/boost/type_traits//boost_type_traits
/boost/winapi//boost_winapi ;

project /boost/dll
Expand Down
38 changes: 16 additions & 22 deletions include/boost/dll/detail/aggressive_ptr_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
# pragma once
#endif

#include <boost/core/addressof.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_member_pointer.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <cstring> // std::memcpy
#include <memory>
#include <type_traits>

#if defined(__GNUC__) && defined(__GNUC_MINOR__) && (__GNUC__ * 100 + __GNUC_MINOR__ > 301)
# pragma GCC system_header
Expand All @@ -32,16 +26,16 @@ namespace boost { namespace dll { namespace detail {
// GCC warns when reinterpret_cast between function pointer and object pointer occur.
// This method suppress the warnings and ensures that such casts are safe.
template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<boost::is_member_pointer<To>::value || boost::is_reference<To>::value || boost::is_member_pointer<From>::value, To>::type
BOOST_FORCEINLINE typename std::enable_if<!std::is_member_pointer<To>::value && !std::is_reference<To>::value && !std::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From v) noexcept
{
static_assert(
boost::is_pointer<To>::value && boost::is_pointer<From>::value,
std::is_pointer<To>::value && std::is_pointer<From>::value,
"`agressive_ptr_cast` function must be used only for pointer casting."
);

static_assert(
boost::is_void< typename boost::remove_pointer<To>::type >::value
std::is_void< typename std::remove_pointer<To>::type >::value
|| boost::is_void< typename boost::remove_pointer<From>::type >::value,
"`agressive_ptr_cast` function must be used only for casting to or from void pointers."
);
Expand All @@ -60,25 +54,25 @@ BOOST_FORCEINLINE typename boost::disable_if_c<boost::is_member_pointer<To>::val
#endif

template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_reference<To>::value || boost::is_member_pointer<From>::value, To>::type
BOOST_FORCEINLINE typename std::enable_if<std::is_reference<To>::value && !std::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From v) noexcept
{
static_assert(
boost::is_pointer<From>::value,
std::is_pointer<From>::value,
"`agressive_ptr_cast` function must be used only for pointer casting."
);

static_assert(
boost::is_void< typename boost::remove_pointer<From>::type >::value,
std::is_void< typename std::remove_pointer<From>::type >::value,
"`agressive_ptr_cast` function must be used only for casting to or from void pointers."
);

static_assert(
sizeof(v) == sizeof(typename boost::remove_reference<To>::type*),
sizeof(v) == sizeof(typename std::remove_reference<To>::type*),
"Pointer to function and pointer to object differ in size on your platform."
);
return static_cast<To>(
**reinterpret_cast<typename boost::remove_reference<To>::type**>(
**reinterpret_cast<typename std::remove_reference<To>::type**>(
v
)
);
Expand All @@ -89,16 +83,16 @@ BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_reference<To>::value |
#endif

template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_member_pointer<To>::value || boost::is_member_pointer<From>::value, To>::type
BOOST_FORCEINLINE typename std::enable_if<std::is_member_pointer<To>::value && !std::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From v) noexcept
{
static_assert(
boost::is_pointer<From>::value,
std::is_pointer<From>::value,
"`agressive_ptr_cast` function must be used only for pointer casting."
);

static_assert(
boost::is_void< typename boost::remove_pointer<From>::type >::value,
std::is_void< typename boost::remove_pointer<From>::type >::value,
"`agressive_ptr_cast` function must be used only for casting to or from void pointers."
);

Expand All @@ -108,16 +102,16 @@ BOOST_FORCEINLINE typename boost::disable_if_c<!boost::is_member_pointer<To>::va
}

template <class To, class From>
BOOST_FORCEINLINE typename boost::disable_if_c<boost::is_member_pointer<To>::value || !boost::is_member_pointer<From>::value, To>::type
BOOST_FORCEINLINE typename std::enable_if<!std::is_member_pointer<To>::value && std::is_member_pointer<From>::value, To>::type
aggressive_ptr_cast(From /* v */) noexcept
{
static_assert(
boost::is_pointer<To>::value,
std::is_pointer<To>::value,
"`agressive_ptr_cast` function must be used only for pointer casting."
);

static_assert(
boost::is_void< typename boost::remove_pointer<To>::type >::value,
std::is_void< typename std::remove_pointer<To>::type >::value,
"`agressive_ptr_cast` function must be used only for casting to or from void pointers."
);

Expand Down
6 changes: 1 addition & 5 deletions include/boost/dll/detail/demangling/itanium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
#define BOOST_DLL_DETAIL_DEMANGLING_ITANIUM_HPP_

#include <boost/dll/detail/demangling/mangled_storage_base.hpp>

#include <iterator>
#include <algorithm>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/function_traits.hpp>


namespace boost { namespace dll { namespace detail {
Expand Down
4 changes: 3 additions & 1 deletion include/boost/dll/detail/demangling/mangled_storage_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include <vector>
#include <string>
#include <map>
#include <type_traits>

#include <boost/dll/detail/demangling/demangle_symbol.hpp>
#include <boost/dll/library_info.hpp>
#include <boost/type_index/ctti_type_index.hpp>
#include <boost/type_traits/remove_reference.hpp>


namespace boost { namespace dll { namespace detail {

Expand Down
6 changes: 0 additions & 6 deletions include/boost/dll/detail/demangling/msvc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
#include <boost/dll/detail/demangling/mangled_storage_base.hpp>
#include <iterator>
#include <algorithm>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_volatile.hpp>
#include <boost/type_traits/is_lvalue_reference.hpp>
#include <boost/type_traits/is_rvalue_reference.hpp>
#include <boost/type_traits/function_traits.hpp>
#include <boost/type_traits/remove_reference.hpp>

#include <boost/spirit/home/x3.hpp>

Expand Down
60 changes: 28 additions & 32 deletions include/boost/dll/detail/import_mangled_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
#define BOOST_DLL_DETAIL_IMPORT_MANGLED_HELPERS_HPP_


#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <type_traits>


#ifdef BOOST_HAS_PRAGMA_ONCE
Expand All @@ -34,9 +30,9 @@ struct push_front<Value, sequence<Args...>>

template<class Lhs, class Rhs>
struct unqalified_is_same :
boost::is_same<
typename boost::remove_cv<Lhs>::type,
typename boost::remove_cv<Rhs>::type
std::is_same<
typename std::remove_cv<Lhs>::type,
typename std::remove_cv<Rhs>::type
>
{
};
Expand All @@ -48,19 +44,19 @@ template<class T> struct is_function_seq;

//type-trait for function overloads
template<class Class, class...Args> struct is_function_seq<sequence<Class, Args...>>
: boost::conditional<
boost::is_function<Class>::value,
: std::conditional<
std::is_function<Class>::value,
is_function_seq<sequence<Args...>>,
boost::false_type>::type
std::false_type>::type
{};

template<class Class>
struct is_function_seq<sequence<Class>> : boost::is_function<Class>
struct is_function_seq<sequence<Class>> : std::is_function<Class>
{
};

template<>
struct is_function_seq<sequence<>> : boost::false_type
struct is_function_seq<sequence<>> : std::false_type
{
};

Expand Down Expand Up @@ -151,11 +147,11 @@ struct make_mem_fn_seq<T0, T1, T2, Args...>
* Class, const Class, void(int)//--> ovl class.
*
*/
static_assert(boost::is_object<T0>::value, "");
static_assert(std::is_object<T0>::value, "");
typedef typename make_mem_fn_seq_getter<
unqalified_is_same<T0, T1>::value, T0, T1, T2>::type mem_fn_type;

typedef typename boost::conditional<
typedef typename std::conditional<
unqalified_is_same<T0, T1>::value,
make_mem_fn_seq<T1, Args...>,
make_mem_fn_seq<T0, T2, Args...>> ::type next;
Expand Down Expand Up @@ -203,46 +199,46 @@ struct make_mem_fn_seq<T0, T1, T2, Args...>
template<class T, class U, class ...Args>
struct is_mem_fn_seq_impl
{
typedef typename boost::conditional<
boost::is_function<U>::value || boost::dll::experimental::detail::unqalified_is_same<T, U>::value,
typedef typename std::conditional<
std::is_function<U>::value || boost::dll::experimental::detail::unqalified_is_same<T, U>::value,
typename is_mem_fn_seq_impl<T, Args...>::type,
boost::false_type>::type type;
std::false_type>::type type;
};

template<class T, class U>
struct is_mem_fn_seq_impl<T, U>
{
typedef typename boost::conditional<
boost::is_function<U>::value && boost::is_object<T>::value,
boost::true_type, boost::false_type>::type type;
typedef typename std::conditional<
std::is_function<U>::value && std::is_object<T>::value,
std::true_type, std::false_type>::type type;
};

template<class T, class U, class Last>
struct is_mem_fn_seq_impl<T, U, Last>
{
typedef typename boost::conditional<
(boost::is_function<U>::value || boost::dll::experimental::detail::unqalified_is_same<T, U>::value)
&& boost::is_function<Last>::value,
boost::true_type, boost::false_type>::type type;
typedef typename std::conditional<
(std::is_function<U>::value || boost::dll::experimental::detail::unqalified_is_same<T, U>::value)
&& std::is_function<Last>::value,
std::true_type, std::false_type>::type type;
};

template<class T> struct is_mem_fn_seq : boost::false_type {};
template<class T> struct is_mem_fn_seq : std::false_type {};

//If only two arguments are provided at all.
template<class T, class U>
struct is_mem_fn_seq<sequence<T, U>> : boost::conditional<
boost::is_object<T>::value && boost::is_function<U>::value,
boost::true_type, boost::false_type>::type
struct is_mem_fn_seq<sequence<T, U>> : std::conditional<
std::is_object<T>::value && std::is_function<U>::value,
std::true_type, std::false_type>::type
{
};


template<class T, class Func, class ...Args>
struct is_mem_fn_seq<sequence<T, Func, Args...>> :
boost::conditional<
boost::is_class<T>::value && boost::is_function<Func>::value,
std::conditional<
std::is_class<T>::value && std::is_function<Func>::value,
typename is_mem_fn_seq_impl<T, Args...>::type,
boost::false_type>::type {};
std::false_type>::type {};


/* ********************************** mem fn sequence tuple ******************************/
Expand Down
14 changes: 7 additions & 7 deletions include/boost/dll/import.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#define BOOST_DLL_IMPORT_HPP

#include <boost/dll/config.hpp>
#include <boost/core/addressof.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/type_traits/is_object.hpp>
#include <boost/make_shared.hpp>
#include <boost/dll/shared_library.hpp>

#include <memory> // std::addressof
#include <type_traits>

#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace detail {

template <class T>
using import_type = typename std::conditional<
boost::is_object<T>::value,
std::is_object<T>::value,
boost::shared_ptr<T>,
boost::dll::detail::library_function<T>
>::type;
Expand Down Expand Up @@ -111,7 +111,7 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const boost::dll::fs::path& lib, cons
using type = boost::dll::detail::import_type<T>;

auto p = boost::make_shared<boost::dll::shared_library>(lib, mode);
return type(p, boost::addressof(p->get<T>(name)));
return type(p, std::addressof(p->get<T>(name)));
}

//! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode)
Expand All @@ -128,7 +128,7 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const shared_library& lib, const char
using type = boost::dll::detail::import_type<T>;

auto p = boost::make_shared<boost::dll::shared_library>(lib);
return type(p, boost::addressof(p->get<T>(name)));
return type(p, std::addressof(p->get<T>(name)));
}

//! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode)
Expand All @@ -145,7 +145,7 @@ BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const char* nam
auto p = boost::make_shared<boost::dll::shared_library>(
std::move(lib)
);
return type(p, boost::addressof(p->get<T>(name)));
return type(p, std::addressof(p->get<T>(name)));
}

//! \overload boost::dll::import_symbol(const boost::dll::fs::path& lib, const char* name, load_mode::type mode)
Expand Down
Loading

0 comments on commit d80110d

Please sign in to comment.