#ifndef EXTENDED_ALGORITHMS_H #define EXTENDED_ALGORITHMS_H #include #include #include #include #include #include #include #include #if defined(FASTOR_UNIX_OS) #include #endif namespace Fastor { // Implementation of STL iota to work on other types such as // std::complex. For std::complex iota_impl increments the real // part only template inline void iota_impl(ForwardIt first, ForwardIt last, T value) { while(first != last) { *first++ = value; value += T(1); } } template inline std::array argsort(const std::array &v) { std::array idx; std::iota(idx.begin(),idx.end(),0); std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] < v[i2];}); return idx; } template::value,bool>::type = 0> inline std::string itoa(const std::array& arr) { std::string out = std::to_string(arr[0]); for (size_t i=1; i inline constexpr int signum(T x, [[gnu::unused]] std::false_type is_signed) { return T(0) < x; } template inline constexpr int signum(T x, [[gnu::unused]] std::true_type is_signed) { return (T(0) < x) - (x < T(0)); } template inline constexpr int signum(T x) { return signum(x, std::is_signed()); } // Get a string +/- based on sign template std::string signum_string(T val) { return signum(val) == 1 ? "+" : "-"; } } // end of namespace Fastor #endif // EXTENDED_ALGORITHMS_H