Hacker News new | past | comments | ask | show | jobs | submit login

Concepts will accomplish this when they finally make it into the standard.



Concepts will certainly be nice once they arrive in the standard, but it is already possible today with some trickery. Example checking whether an std::vector<T>'s type is comparable with `operator<`: http://coliru.stacked-crooked.com/a/2ea46e0afd894d3d

The error you get if you try to sort a vector with an unordered type is relatively easy to read:

    main.cpp: In instantiation of 'void merge_sort(std::vector<_RealType>&) [with T = type]':
    main.cpp:45:17:   required from here
    main.cpp:30:5: error: static assertion failed: Element type is not sortable
         static_assert( concept::is_ord<T>(), "Element type is not sortable" );
         ^




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: