Skip to content

Another look at integral and floating_point #631

@cjdb

Description

@cjdb

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions