algorithm_constexpr.cpp 675 B

123456789101112131415161718192021
  1. #include <cxxomfort/cxxomfort.hpp>
  2. #include <cxxomfort/algorithm.hpp> // hash
  3. #include <cxxomfort/iterator.hpp>
  4. #include <cxxomfort/array.hpp>
  5. #include <iostream>
  6. constexpr cxxomfort::array<int,8> nums = { {4, -7, 1, 8, -2, -3, 6, 2} };
  7. constexpr bool is_pos (int x) noexcept { return x > 0; }
  8. int main () {
  9. using namespace std;
  10. using cxxomfort::constexpr_tag;
  11. constexpr unsigned positives = cxxomfort::fix::count_if( constexpr_tag
  12. , nums.cbegin(), nums.cend(), is_pos);
  13. static_assert( positives == 5, "positives");
  14. constexpr int const * pf = cxxomfort::fix::find( constexpr_tag
  15. , nums.cbegin(), nums.cend(), 8 );
  16. static_assert( pf == nums.cbegin()+3, "find");
  17. }