boostorg / boostorg/type_traits
add is_quotrem_order
- Dominant language
- C++
- Stars
- 66
- Forks
- 87
- PR merge metrics
- No merged PRs in 30d
Description
Problem:
std::Xdiv_t can be implemented as {quot, rem} or {rem, quot} (what a mess). This means that structured binding are not unique:
auto [a, b] = std::div(x, y);
is a quot or rem or is b quot or rem ?
is_quotrem_order.hpp
```
// Distributed under the Boost Software License Version 1.0 https://www.boost.org/LICENSE_1_0.txt
// Copyright Gero Peterhoff
#ifndef BOOST_TYPE_TRAITS_IS_QUOTREM_ORDER_HPP
#define BOOST_TYPE_TRAITS_IS_QUOTREM_ORDER_HPP
#include
#include
#include
namespace boost
{
namespace detail
{
template
inline constexpr bool is_quotrem_order() noexcept
{
static_assert(std::is_arithmetic::value, "invalid type");
// std::div need signed integer
using value_type = typename std::conditional_t
<
std::is_floating_point::value || boost::is_bool::value,
int,
typename std::make_signed::type
>;
using div_type = decltype(std::div(value_type{}, value_type{}));
constexpr div_type
div{value_type{0}, value_type{1}};
return div.quot == value_type{0};
}
} // detail
template struct is_quotrem_order : public std::integral_constant
<
bool,
detail::is_quotrem_order()
> {};
#if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template inline constexpr bool is_quotrem_order_v = is_quotrem_order::value;
#endif
} // boost
#endif // BOOST_TYPE_TRAITS_IS_QUOTREM_ORDER_HPP
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.