Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_integer #186

Closed
gpeterhoff opened this issue Feb 4, 2024 · 3 comments
Closed

add is_integer #186

gpeterhoff opened this issue Feb 4, 2024 · 3 comments

Comments

@gpeterhoff
Copy link

gpeterhoff commented Feb 4, 2024

is_integer.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_INTEGER_HPP
#define BOOST_TYPE_TRAITS_IS_INTEGER_HPP

#include <boost/type_traits/remove_cvref.hpp>
#include <boost/type_traits/is_unsigned.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/cstdint.hpp>


namespace boost
{
template <typename Type> struct is_integer			: public false_type{};
template <typename Type> struct is_integer<volatile const Type>	: public is_integer<Type>{};
template <typename Type> struct is_integer<volatile Type>	: public is_integer<Type>{};
template <typename Type> struct is_integer<const Type>		: public is_integer<Type>{};

#if defined(BOOST_HAS_INT128)
template <> struct is_integer<boost::uint128_type>	: public true_type{};
template <> struct is_integer<boost::int128_type>	: public true_type{};
#endif

template <> struct is_integer<uint64_t>	: public true_type{};
template <> struct is_integer<int64_t>	: public true_type{};

template <> struct is_integer<uint32_t>	: public true_type{};
template <> struct is_integer<int32_t>	: public true_type{};

template <> struct is_integer<uint16_t>	: public true_type{};
template <> struct is_integer<int16_t>	: public true_type{};

template <> struct is_integer<uint8_t>	: public true_type{};
template <> struct is_integer<int8_t>	: public true_type{};




template <typename Type> struct is_unsigned_integer : public integral_constant
<
	bool,
	is_integer<Type>::value && is_unsigned<Type>::value
>	{};

template <typename Type> struct is_signed_integer : public integral_constant
<
	bool,
	is_integer<Type>::value && is_signed<Type>::value
>	{};



#if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template <typename Type> inline constexpr bool is_unsigned_integer_v	= is_unsigned_integer<Type>::value;
template <typename Type> inline constexpr bool is_signed_integer_v	= is_signed_integer<Type>::value;
template <typename Type> inline constexpr bool is_integer_v		= is_integer<Type>::value;
#endif
}	//	boost

#endif	//	BOOST_TYPE_TRAITS_IS_INTEGER_HPP
@jzmaddock
Copy link
Collaborator

This is effectively https://www.boost.org/doc/libs/1_84_0/libs/type_traits/doc/html/boost_typetraits/reference/is_integral.html, yes I realise you have a slightly different definition of what constitutes an integer, but was never our intention to provide super-fine grained categorisation.

@gpeterhoff
Copy link
Author

gpeterhoff commented Feb 4, 2024

That's exactly my point.
You haven't thought about it, it doesn't exist in the standard.
There are various use cases for this.

please open this issues

@pdimov
Copy link
Member

pdimov commented Feb 5, 2024

The concept "integer type" does exist in the standard (but not with the above definition which is incorrect). See https://eel.is/c++draft/basic.fundamental#1 and https://eel.is/c++draft/basic.fundamental#2.

Then https://eel.is/c++draft/basic.fundamental#11 muddies the water somewhat, but I think that "signed integer type" + "unsigned integer type" is a better definition for "integer type".

Currently the best approximation of the above is `std::numeric_limits::is_integer", e.g. https://github.com/boostorg/core/blob/0a35bb6a20bd13e85ff492a5be01b3894807a0d1/include/boost/core/bit.hpp#L299.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants