diff options
| author | Martin Hořeňovský | 2021-08-13 14:16:30 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-08-16 16:22:19 +0200 |
| commit | d2ee7100d26128b3956571cc802f3a52c9b9aea8 (patch) | |
| tree | 84845c4a6bbc080c40cdd37ca373b1832aa84159 /src | |
| parent | 03ce304102829d438a0e3249b86094a6da802dfa (diff) | |
| download | catch3-d2ee7100d26128b3956571cc802f3a52c9b9aea8.tar.gz | |
Replace uses of std::move and std::forward with macros
This improves the SelfTest build times by about 3% (measured
with Clang 10 on random Linux box I had lying around).
Diffstat (limited to 'src')
41 files changed, 156 insertions, 129 deletions
diff --git a/src/catch2/benchmark/catch_benchmark.hpp b/src/catch2/benchmark/catch_benchmark.hpp index ae351e52..428a92fd 100644 --- a/src/catch2/benchmark/catch_benchmark.hpp +++ b/src/catch2/benchmark/catch_benchmark.hpp @@ -15,7 +15,7 @@ #include <catch2/internal/catch_context.hpp> #include <catch2/interfaces/catch_interfaces_reporter.hpp> #include <catch2/internal/catch_unique_name.hpp> - +#include <catch2/internal/catch_move_and_forward.hpp> #include <catch2/benchmark/catch_chronometer.hpp> #include <catch2/benchmark/catch_clock.hpp> #include <catch2/benchmark/catch_environment.hpp> @@ -36,11 +36,11 @@ namespace Catch { namespace Benchmark { struct Benchmark { Benchmark(std::string&& benchmarkName) - : name(std::move(benchmarkName)) {} + : name(CATCH_MOVE(benchmarkName)) {} template <class FUN> Benchmark(std::string&& benchmarkName , FUN &&func) - : fun(std::move(func)), name(std::move(benchmarkName)) {} + : fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {} template <typename Clock> ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const { diff --git a/src/catch2/benchmark/catch_chronometer.hpp b/src/catch2/benchmark/catch_chronometer.hpp index 10fd5a27..7ef08cef 100644 --- a/src/catch2/benchmark/catch_chronometer.hpp +++ b/src/catch2/benchmark/catch_chronometer.hpp @@ -14,6 +14,7 @@ #include <catch2/benchmark/catch_optimizer.hpp> #include <catch2/benchmark/detail/catch_complete_invoke.hpp> #include <catch2/internal/catch_meta.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> namespace Catch { namespace Benchmark { @@ -42,7 +43,7 @@ namespace Catch { struct Chronometer { public: template <typename Fun> - void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); } + void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); } int runs() const { return repeats; } diff --git a/src/catch2/benchmark/catch_constructor.hpp b/src/catch2/benchmark/catch_constructor.hpp index fe651f1c..43b59212 100644 --- a/src/catch2/benchmark/catch_constructor.hpp +++ b/src/catch2/benchmark/catch_constructor.hpp @@ -10,8 +10,9 @@ #ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED #define CATCH_CONSTRUCTOR_HPP_INCLUDED +#include <catch2/internal/catch_move_and_forward.hpp> + #include <type_traits> -#include <utility> namespace Catch { namespace Benchmark { @@ -30,7 +31,7 @@ namespace Catch { ObjectStorage(ObjectStorage&& other) { - new(&data) T(std::move(other.stored_object())); + new(&data) T(CATCH_MOVE(other.stored_object())); } ~ObjectStorage() { destruct_on_exit<T>(); } @@ -38,7 +39,7 @@ namespace Catch { template <typename... Args> void construct(Args&&... args) { - new (&data) T(std::forward<Args>(args)...); + new (&data) T(CATCH_FORWARD(args)...); } template <bool AllowManualDestruction = !Destruct> diff --git a/src/catch2/benchmark/catch_optimizer.hpp b/src/catch2/benchmark/catch_optimizer.hpp index 6f03ea0d..381626da 100644 --- a/src/catch2/benchmark/catch_optimizer.hpp +++ b/src/catch2/benchmark/catch_optimizer.hpp @@ -14,8 +14,9 @@ # include <atomic> // atomic_thread_fence #endif +#include <catch2/internal/catch_move_and_forward.hpp> + #include <type_traits> -#include <utility> namespace Catch { namespace Benchmark { @@ -57,12 +58,12 @@ namespace Catch { template <typename Fn, typename... Args> inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type { - deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...))); + deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...)); } template <typename Fn, typename... Args> inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type { - std::forward<Fn>(fn) (std::forward<Args...>(args...)); + CATCH_FORWARD(fn) (CATCH_FORWARD(args)...); } } // namespace Benchmark } // namespace Catch diff --git a/src/catch2/benchmark/catch_sample_analysis.hpp b/src/catch2/benchmark/catch_sample_analysis.hpp index 579e7af9..6204aaf1 100644 --- a/src/catch2/benchmark/catch_sample_analysis.hpp +++ b/src/catch2/benchmark/catch_sample_analysis.hpp @@ -13,10 +13,10 @@ #include <catch2/benchmark/catch_clock.hpp> #include <catch2/benchmark/catch_estimate.hpp> #include <catch2/benchmark/catch_outlier_classification.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <algorithm> #include <vector> -#include <string> #include <iterator> namespace Catch { @@ -35,7 +35,7 @@ namespace Catch { samples2.reserve(samples.size()); std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); }); return { - std::move(samples2), + CATCH_MOVE(samples2), mean, standard_deviation, outliers, diff --git a/src/catch2/benchmark/detail/catch_analyse.hpp b/src/catch2/benchmark/detail/catch_analyse.hpp index 46382c62..cf96a3d2 100644 --- a/src/catch2/benchmark/detail/catch_analyse.hpp +++ b/src/catch2/benchmark/detail/catch_analyse.hpp @@ -15,6 +15,7 @@ #include <catch2/benchmark/catch_sample_analysis.hpp> #include <catch2/benchmark/detail/catch_stats.hpp> #include <catch2/interfaces/catch_interfaces_config.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <algorithm> #include <iterator> @@ -45,7 +46,7 @@ namespace Catch { samples2.reserve(samples.size()); std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); }); return { - std::move(samples2), + CATCH_MOVE(samples2), wrap_estimate(analysis.mean), wrap_estimate(analysis.standard_deviation), outliers, @@ -64,7 +65,7 @@ namespace Catch { mean /= i; return { - std::move(samples), + CATCH_MOVE(samples), Estimate<Duration>{mean, mean, mean, 0.0}, Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0}, OutlierClassification{}, diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/src/catch2/benchmark/detail/catch_benchmark_function.hpp index 4e0c55ff..ccfdc59d 100644 --- a/src/catch2/benchmark/detail/catch_benchmark_function.hpp +++ b/src/catch2/benchmark/detail/catch_benchmark_function.hpp @@ -14,8 +14,8 @@ #include <catch2/benchmark/detail/catch_complete_invoke.hpp> #include <catch2/internal/catch_meta.hpp> #include <catch2/internal/catch_unique_ptr.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> -#include <cassert> #include <type_traits> #include <utility> @@ -48,7 +48,7 @@ namespace Catch { }; template <typename Fun> struct model : public callable { - model(Fun&& fun_) : fun(std::move(fun_)) {} + model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {} model(Fun const& fun_) : fun(fun_) {} model<Fun>* clone() const override { return new model<Fun>(*this); } @@ -78,17 +78,17 @@ namespace Catch { template <typename Fun, typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0> BenchmarkFunction(Fun&& fun) - : f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {} + : f(new model<typename std::decay<Fun>::type>(CATCH_FORWARD(fun))) {} BenchmarkFunction( BenchmarkFunction&& that ) noexcept: - f( std::move( that.f ) ) {} + f( CATCH_MOVE( that.f ) ) {} BenchmarkFunction(BenchmarkFunction const& that) : f(that.f->clone()) {} BenchmarkFunction& operator=( BenchmarkFunction&& that ) noexcept { - f = std::move( that.f ); + f = CATCH_MOVE( that.f ); return *this; } diff --git a/src/catch2/benchmark/detail/catch_complete_invoke.hpp b/src/catch2/benchmark/detail/catch_complete_invoke.hpp index e5af9465..700885d0 100644 --- a/src/catch2/benchmark/detail/catch_complete_invoke.hpp +++ b/src/catch2/benchmark/detail/catch_complete_invoke.hpp @@ -14,6 +14,7 @@ #include <catch2/internal/catch_meta.hpp> #include <catch2/interfaces/catch_interfaces_capture.hpp> #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <type_traits> #include <utility> @@ -33,14 +34,14 @@ namespace Catch { struct CompleteInvoker { template <typename Fun, typename... Args> static Result invoke(Fun&& fun, Args&&... args) { - return std::forward<Fun>(fun)(std::forward<Args>(args)...); + return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...); } }; template <> struct CompleteInvoker<void> { template <typename Fun, typename... Args> static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) { - std::forward<Fun>(fun)(std::forward<Args>(args)...); + CATCH_FORWARD(fun)(CATCH_FORWARD(args)...); return {}; } }; @@ -48,14 +49,14 @@ namespace Catch { // invoke and not return void :( template <typename Fun, typename... Args> CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) { - return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...); + return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...); } } // namespace Detail template <typename Fun> Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) { - return Detail::complete_invoke(std::forward<Fun>(fun)); + return Detail::complete_invoke(CATCH_FORWARD(fun)); } } // namespace Benchmark } // namespace Catch diff --git a/src/catch2/benchmark/detail/catch_measure.hpp b/src/catch2/benchmark/detail/catch_measure.hpp index 49df259a..739e91e5 100644 --- a/src/catch2/benchmark/detail/catch_measure.hpp +++ b/src/catch2/benchmark/detail/catch_measure.hpp @@ -13,8 +13,7 @@ #include <catch2/benchmark/catch_clock.hpp> #include <catch2/benchmark/detail/catch_complete_invoke.hpp> #include <catch2/benchmark/detail/catch_timing.hpp> - -#include <utility> +#include <catch2/internal/catch_move_and_forward.hpp> namespace Catch { namespace Benchmark { @@ -22,10 +21,10 @@ namespace Catch { template <typename Clock, typename Fun, typename... Args> TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) { auto start = Clock::now(); - auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...); + auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...); auto end = Clock::now(); auto delta = end - start; - return { delta, std::forward<decltype(r)>(r), 1 }; + return { delta, CATCH_FORWARD(r), 1 }; } } // namespace Detail } // namespace Benchmark diff --git a/src/catch2/benchmark/detail/catch_repeat.hpp b/src/catch2/benchmark/detail/catch_repeat.hpp index cc2ea024..cbb77e2f 100644 --- a/src/catch2/benchmark/detail/catch_repeat.hpp +++ b/src/catch2/benchmark/detail/catch_repeat.hpp @@ -11,7 +11,7 @@ #define CATCH_REPEAT_HPP_INCLUDED #include <type_traits> -#include <utility> +#include <catch2/internal/catch_move_and_forward.hpp> namespace Catch { namespace Benchmark { @@ -27,7 +27,7 @@ namespace Catch { }; template <typename Fun> repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) { - return { std::forward<Fun>(fun) }; + return { CATCH_FORWARD(fun) }; } } // namespace Detail } // namespace Benchmark diff --git a/src/catch2/benchmark/detail/catch_run_for_at_least.hpp b/src/catch2/benchmark/detail/catch_run_for_at_least.hpp index 4b73ad97..f9f7ad53 100644 --- a/src/catch2/benchmark/detail/catch_run_for_at_least.hpp +++ b/src/catch2/benchmark/detail/catch_run_for_at_least.hpp @@ -16,8 +16,8 @@ #include <catch2/benchmark/detail/catch_complete_invoke.hpp> #include <catch2/benchmark/detail/catch_timing.hpp> #include <catch2/internal/catch_meta.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> -#include <utility> #include <type_traits> namespace Catch { @@ -32,7 +32,7 @@ namespace Catch { Detail::ChronometerModel<Clock> meter; auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters)); - return { meter.elapsed(), std::move(result), iters }; + return { meter.elapsed(), CATCH_MOVE(result), iters }; } template <typename Clock, typename Fun> @@ -52,7 +52,7 @@ namespace Catch { auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>()); if (Timing.elapsed >= how_long) { - return { Timing.elapsed, std::move(Timing.result), iters }; + return { Timing.elapsed, CATCH_MOVE(Timing.result), iters }; } iters *= 2; } diff --git a/src/catch2/catch_message.cpp b/src/catch2/catch_message.cpp index 2a35da1d..2ad4aea3 100644 --- a/src/catch2/catch_message.cpp +++ b/src/catch2/catch_message.cpp @@ -9,6 +9,7 @@ #include <catch2/interfaces/catch_interfaces_capture.hpp> #include <catch2/internal/catch_uncaught_exceptions.hpp> #include <catch2/internal/catch_enforce.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <cassert> #include <stack> @@ -25,7 +26,7 @@ namespace Catch { } ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept: - m_info( std::move( old.m_info ) ) { + m_info( CATCH_MOVE( old.m_info ) ) { old.m_moved = true; } diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp index c183600a..edf9b2b5 100644 --- a/src/catch2/catch_registry_hub.cpp +++ b/src/catch2/catch_registry_hub.cpp @@ -19,6 +19,7 @@ #include <catch2/catch_test_case_info.hpp> #include <catch2/internal/catch_noncopyable.hpp> #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> namespace Catch { @@ -48,16 +49,16 @@ namespace Catch { public: // IMutableRegistryHub void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override { - m_reporterRegistry.registerReporter( name, std::move(factory) ); + m_reporterRegistry.registerReporter( name, CATCH_MOVE(factory) ); } void registerListener( IReporterFactoryPtr factory ) override { - m_reporterRegistry.registerListener( std::move(factory) ); + m_reporterRegistry.registerListener( CATCH_MOVE(factory) ); } void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override { - m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) ); + m_testCaseRegistry.registerTest( CATCH_MOVE(testInfo), CATCH_MOVE(invoker) ); } void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) override { - m_exceptionTranslatorRegistry.registerTranslator( std::move(translator) ); + m_exceptionTranslatorRegistry.registerTranslator( CATCH_MOVE(translator) ); } void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { m_tagAliasRegistry.add( alias, tag, lineInfo ); diff --git a/src/catch2/catch_section_info.hpp b/src/catch2/catch_section_info.hpp index b80d8b92..1d206891 100644 --- a/src/catch2/catch_section_info.hpp +++ b/src/catch2/catch_section_info.hpp @@ -23,7 +23,7 @@ namespace Catch { // still use the `-c` flag comfortably. SectionInfo( SourceLineInfo const& _lineInfo, std::string _name, const char* const = nullptr ): - name(std::move(_name)), + name(CATCH_MOVE(_name)), lineInfo(_lineInfo) {} diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index 4419da4c..6ce21803 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -21,6 +21,7 @@ #include <catch2/reporters/catch_reporter_listening.hpp> #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/interfaces/catch_interfaces_reporter_factory.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <algorithm> #include <iomanip> @@ -57,7 +58,7 @@ namespace Catch { explicit TestGroup(IStreamingReporterPtr&& reporter, Config const* config): m_reporter(reporter.get()), m_config{config}, - m_context{config, std::move(reporter)} { + m_context{config, CATCH_MOVE(reporter)} { auto const& allTestCases = getAllTestCasesSorted(*m_config); m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config); @@ -277,7 +278,7 @@ namespace Catch { return 0; } - TestGroup tests { std::move(reporter), m_config.get() }; + TestGroup tests { CATCH_MOVE(reporter), m_config.get() }; auto const totals = tests.execute(); if( m_config->warnAboutNoTests() && totals.error == -1 ) diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index 4ac73005..13786b77 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -11,6 +11,7 @@ #include <catch2/interfaces/catch_interfaces_generatortracker.hpp> #include <catch2/internal/catch_source_line_info.hpp> #include <catch2/internal/catch_stringref.hpp> +#include <catch2/internal/catch_move_and_forward.hpp> #include <vector> #include <tuple> @@ -55,7 +56,7 @@ namespace Detail { GeneratorWrapper(IGenerator<T>* generator): m_generator(generator) {} GeneratorWrapper(GeneratorPtr<T> generator): - m_generator(std::move(generator)) {} + m_generator(CATCH_MOVE(generator)) {} T const& get() const { return m_generator->get(); @@ -74,7 +75,7 @@ namespace Detail { m_value(value) {} SingleValueGenerator(T&& value): - m_value(std::move(value)) + m_value(CATCH_MOVE(value)) {} T const& get() const override { @@ -108,7 +109,7 @@ namespace Detail { GeneratorWrapper<DecayedT> value( T&& value ) { return GeneratorWrapper<DecayedT>( Catch::Detail::make_unique<SingleValueGenerator<DecayedT>>( - std::forward<T>( value ) ) ); + CATCH_FORWARD( |