Skip to content
Open
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
61 changes: 61 additions & 0 deletions include/boost/beast2/detail/call_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
// Official repository: https://github.com/cppalliance/beast2
//

#ifndef BOOST_BEAST2_DETAIL_CALL_TRAITS_HPP
#define BOOST_BEAST2_DETAIL_CALL_TRAITS_HPP

namespace boost {
namespace beast2 {
namespace detail {

template<class... Ts> struct type_list {};

template<class T> struct call_traits;

template<class R, class... Args>
struct call_traits<R(*)(Args...)>
{
using return_type = R;
using arg_types = type_list<Args...>;
};

template<class R, class... Args>
struct call_traits<R(&)(Args...)>
{
using return_type = R;
using arg_types = type_list<Args...>;
};

template<class C, class R, class... Args>
struct call_traits<R(C::*)(Args...)>
{
using class_type = C;
using return_type = R ;
using arg_types = type_list<Args...>;
};

template<class C, class R, class... Args>
struct call_traits<R(C::*)(Args...) const>
{
using class_type = C;
using return_type = R ;
using arg_types = type_list<Args...>;
};

template<class F>
struct call_traits
: call_traits<decltype(&F::operator())>
{
};

} // detail
} // beast2
} // boost

#endif
5 changes: 4 additions & 1 deletion include/boost/beast2/detail/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ namespace boost {
namespace beast2 {
namespace detail {

BOOST_BEAST2_DECL void BOOST_NORETURN throw_logic_error(
BOOST_BEAST2_DECL void BOOST_NORETURN throw_bad_typeid(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_BEAST2_DECL void BOOST_NORETURN throw_invalid_argument(
source_location const& loc = BOOST_CURRENT_LOCATION);

BOOST_BEAST2_DECL void BOOST_NORETURN throw_logic_error(
source_location const& loc = BOOST_CURRENT_LOCATION);

} // detail
} // beast2
} // boost
Expand Down
39 changes: 39 additions & 0 deletions include/boost/beast2/detail/get_key_type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
// Official repository: https://github.com/cppalliance/beast2
//

#ifndef BOOST_BEAST2_DETAIL_GET_KEY_TYPE_HPP
#define BOOST_BEAST2_DETAIL_GET_KEY_TYPE_HPP

namespace boost {
namespace beast2 {
namespace detail {

template<class T, class = void>
struct get_key_type_impl
{
using type = T;
};

template<class T>
struct get_key_type_impl<T,
decltype(void(typename T::key_type()))>
{
using type = typename T::key_type;
};

// Alias for T::key_type if it exists, otherwise T
template<class T>
using get_key_type =
typename get_key_type_impl<T>::type;

} // detail
} // beast2
} // boost

#endif
75 changes: 75 additions & 0 deletions include/boost/beast2/detail/type_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// 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)
//
// Official repository: https://github.com/cppalliance/beast2
//

#ifndef BOOST_BEAST2_DETAIL_TYPE_INFO_HPP
#define BOOST_BEAST2_DETAIL_TYPE_INFO_HPP

#include <cstdint>
#ifndef BOOST_NO_RTTI
#include <typeinfo>
#endif

namespace boost {
namespace beast2 {
namespace detail {

#ifdef BOOST_NO_RTTI

struct type_info
{
std::size_t hash_code() const noexcept
{
return reinterpret_cast<std::uintptr_t>(this);
}

friend bool operator==(type_info const& lhs,
type_info const& rhs) noexcept
{
return &lhs == &rhs;
}

friend bool operator!=(type_info const& lhs,
type_info const& rhs) noexcept
{
return &lhs != &rhs;
}
};

template<class T>
struct type_info_for
{
static type_info const value;
};

template<class T>
type_info const type_info_for<T>::value{};

template<class T>
type_info const& get_type_info() noexcept
{
return type_info_for<T>::value;
}

#else

using type_info = std::type_info;

template<class T>
type_info const& get_type_info() noexcept
{
return typeid(T);
}

#endif

} // detail
} // beast2
} // boost

#endif
Loading
Loading