diff --git a/src/core/include/mp-units/ext/algorithm.h b/src/core/include/mp-units/ext/algorithm.h index 4161cbb9..576f1205 100644 --- a/src/core/include/mp-units/ext/algorithm.h +++ b/src/core/include/mp-units/ext/algorithm.h @@ -20,6 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// Copy-pasted C++ standard libraries to be replaced with `import std;` when available +// `#include ` is too heavy to do in every translation unit + #pragma once #include // IWYU pragma: keep @@ -33,37 +36,6 @@ namespace mp_units::detail { -// TODO refactor two below functions with std::ranges when moved to modules - - -/** - * @brief Returns the first successful value obtained from applying the function object to the elements of a given - * range, if any. - * - * @tparam InputIt must meet the requirements of LegacyInputIterator - * @tparam UnaryFunction must meet the requirements of MoveConstructible - * @param first the beginning of the range of elements to examine - * @param last the end of the range of elements to examine - * @param f function object, to be applied to the result of dereferencing every iterator in the range - * @return std::invoke_result_t> - */ -template -constexpr std::invoke_result_t> get_first_of(InputIt first, InputIt last, - UnaryFunction f) -{ - for (; first != last; ++first) - if (auto opt = f(*first)) return *opt; - return {}; -} - -template -constexpr auto get_first_of(const Rng& rng, UnaryFunction f) -{ - using std::begin, std::end; - return get_first_of(begin(rng), end(rng), f); -} - -// TODO remove all the below and use std when moved to modules template constexpr InputIt find_first_of(InputIt first, InputIt last, ForwardIt s_first, ForwardIt s_last) { @@ -207,5 +179,4 @@ constexpr copy_result, O> copy(R&& r, O resu return ::mp_units::detail::copy(std::ranges::begin(r), std::ranges::end(r), std::move(result)); } - } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/fixed_string.h b/src/core/include/mp-units/ext/fixed_string.h index 7387fff5..2ff4c745 100644 --- a/src/core/include/mp-units/ext/fixed_string.h +++ b/src/core/include/mp-units/ext/fixed_string.h @@ -20,6 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// To be replaced with: +// P3094: std::basic_fixed_string + #pragma once // TODO use when moved to C++20 modules (parsing takes too long for each translation unit) diff --git a/src/core/include/mp-units/ext/prime.h b/src/core/include/mp-units/ext/prime.h index 9e0baa08..e51f9411 100644 --- a/src/core/include/mp-units/ext/prime.h +++ b/src/core/include/mp-units/ext/prime.h @@ -20,6 +20,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +// To be replaced with: +// P3133: Fast first-factor finding function + #pragma once #include @@ -112,6 +115,22 @@ template return product; } +template +constexpr std::invoke_result_t> get_first_of(InputIt first, InputIt last, + UnaryFunction f) +{ + for (; first != last; ++first) + if (auto opt = f(*first)) return *opt; + return {}; +} + +template +constexpr auto get_first_of(const Rng& rng, UnaryFunction f) +{ + using std::begin, std::end; + return get_first_of(begin(rng), end(rng), f); +} + // A configurable instantiation of the "wheel factorization" algorithm [1] for prime numbers. // // Instantiate with N to use a "basis" of the first N prime numbers. Higher values of N use fewer trial divisions, at diff --git a/src/core/include/mp-units/ext/type_name.h b/src/core/include/mp-units/ext/type_name.h index 24bdc8a6..6cfcca25 100644 --- a/src/core/include/mp-units/ext/type_name.h +++ b/src/core/include/mp-units/ext/type_name.h @@ -1,5 +1,8 @@ // https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c/56766138#56766138 +// To be replaced with: +// P2830: Standardized Constexpr Type Ordering + #pragma once #ifndef MP_UNITS_IN_MODULE_INTERFACE