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

Another look at integral and floating_point #631

Open
cjdb opened this issue Jul 31, 2019 · 1 comment
Open

Another look at integral and floating_point #631

cjdb opened this issue Jul 31, 2019 · 1 comment

Comments

@cjdb
Copy link
Contributor

cjdb commented Jul 31, 2019

cmcstl2 defines integral as:

namespace ext {
   template<class T>
   concept scalar = std::is_scalar_v<T> && regular<T>;

   template<class T>
   concept arithmetic = std::is_arithmetic_v<T> && scalar<T> && totally_ordered<T>;

   template<class T>
   concept floating_point = std::is_floating_point_v<T> && arithmetic<T>;
} // namespace ext

template<class T>
concept integral = std::is_integral_v<T> && ext::arithmetic<T>;

(snake_casing mine)

I think making this standard instead of an extension is probably a Good Thing™️, since our canonical example for regular are the integral types... which don't refine regular, which makes this ambiguous.

template<std::regular T>
void pick_me(T) {}

template<std::integral T>
void pick_me(T) {}

template<std::floating_point T>
void pick_me(T) {}

int main()
{
   pick_me(0);
   pick_me(0.0);
}
@cjdb cjdb changed the title Another look at [X_]integral and floating_point Another look at integral and floating_point Jul 31, 2019
@ericniebler
Copy link
Owner

The downside is that for every test of integral you are now instantiating 3x the number of traits.

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

2 participants