diff options
| author | Martin Hořeňovský | 2020-02-01 21:43:00 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-01 23:34:00 +0100 |
| commit | ea6db670632204bace889f646ca08bfa58bddeab (patch) | |
| tree | e47f559036a91dd062ae6400f2612c398c6a9014 /src/catch2 | |
| parent | a7b3e087a03f6ba33100c842445f16757d545fc0 (diff) | |
| download | catch3-ea6db670632204bace889f646ca08bfa58bddeab.tar.gz | |
Use std::make_unique instead of our polyfill or naked new
The use we previously used the polyfill or naked new is that we
supported C++11, which did not yet have `std::make_unique`. However,
with the move to C++14 as the minimum, `std::make_unique` can be
expected to be always available.
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/catch_enum_values_registry.cpp | 2 | ||||
| -rw-r--r-- | src/catch2/catch_generators.hpp | 14 | ||||
| -rw-r--r-- | src/catch2/catch_generators_generic.hpp | 12 | ||||
| -rw-r--r-- | src/catch2/catch_generators_specific.hpp | 12 | ||||
| -rw-r--r-- | src/catch2/catch_reporter_registrars.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/catch_stream.cpp | 2 |
6 files changed, 18 insertions, 26 deletions
diff --git a/src/catch2/catch_enum_values_registry.cpp b/src/catch2/catch_enum_values_registry.cpp index f7d11860..79261bcf 100644 --- a/src/catch2/catch_enum_values_registry.cpp +++ b/src/catch2/catch_enum_values_registry.cpp @@ -52,7 +52,7 @@ namespace Catch { } std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) { - std::unique_ptr<EnumInfo> enumInfo( new EnumInfo ); + auto enumInfo = std::make_unique<EnumInfo>(); enumInfo->m_name = enumName; enumInfo->m_values.reserve( values.size() ); diff --git a/src/catch2/catch_generators.hpp b/src/catch2/catch_generators.hpp index 3756a719..359db5f4 100644 --- a/src/catch2/catch_generators.hpp +++ b/src/catch2/catch_generators.hpp @@ -33,14 +33,6 @@ public: namespace Generators { - // !TBD move this into its own location? - namespace pf{ - template<typename T, typename... Args> - std::unique_ptr<T> make_unique( Args&&... args ) { - return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); - } - } - template<typename T> struct IGenerator : GeneratorUntypedBase { virtual ~IGenerator() = default; @@ -104,11 +96,11 @@ namespace Generators { template <typename T> GeneratorWrapper<T> value(T&& value) { - return GeneratorWrapper<T>(pf::make_unique<SingleValueGenerator<T>>(std::forward<T>(value))); + return GeneratorWrapper<T>(std::make_unique<SingleValueGenerator<T>>(std::forward<T>(value))); } template <typename T> GeneratorWrapper<T> values(std::initializer_list<T> values) { - return GeneratorWrapper<T>(pf::make_unique<FixedValuesGenerator<T>>(values)); + return GeneratorWrapper<T>(std::make_unique<FixedValuesGenerator<T>>(values)); } template<typename T> @@ -193,7 +185,7 @@ namespace Generators { IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo ); if (!tracker.hasGenerator()) { - tracker.setGenerator(pf::make_unique<Generators<UnderlyingType>>(generatorExpression())); + tracker.setGenerator(std::make_unique<Generators<UnderlyingType>>(generatorExpression())); } auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() ); diff --git a/src/catch2/catch_generators_generic.hpp b/src/catch2/catch_generators_generic.hpp index 3cfa9202..5a8708dc 100644 --- a/src/catch2/catch_generators_generic.hpp +++ b/src/catch2/catch_generators_generic.hpp @@ -46,7 +46,7 @@ namespace Generators { template <typename T> GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(pf::make_unique<TakeGenerator<T>>(target, std::move(generator))); + return GeneratorWrapper<T>(std::make_unique<TakeGenerator<T>>(target, std::move(generator))); } @@ -87,7 +87,7 @@ namespace Generators { template <typename T, typename Predicate> GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(pf::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator)))); + return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(std::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator)))); } template <typename T> @@ -143,7 +143,7 @@ namespace Generators { template <typename T> GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) { - return GeneratorWrapper<T>(pf::make_unique<RepeatGenerator<T>>(repeats, std::move(generator))); + return GeneratorWrapper<T>(std::make_unique<RepeatGenerator<T>>(repeats, std::move(generator))); } template <typename T, typename U, typename Func> @@ -176,14 +176,14 @@ namespace Generators { template <typename Func, typename U, typename T = FunctionReturnType<Func, U>> GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { return GeneratorWrapper<T>( - pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) + std::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) ); } template <typename T, typename U, typename Func> GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { return GeneratorWrapper<T>( - pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) + std::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) ); } @@ -226,7 +226,7 @@ namespace Generators { template <typename T> GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) { return GeneratorWrapper<std::vector<T>>( - pf::make_unique<ChunkGenerator<T>>(size, std::move(generator)) + std::make_unique<ChunkGenerator<T>>(size, std::move(generator)) ); } diff --git a/src/catch2/catch_generators_specific.hpp b/src/catch2/catch_generators_specific.hpp index 0e497c3e..acca7d97 100644 --- a/src/catch2/catch_generators_specific.hpp +++ b/src/catch2/catch_generators_specific.hpp @@ -68,7 +68,7 @@ typename std::enable_if<std::is_integral<T>::value && !std::is_same<T, bool>::va GeneratorWrapper<T>>::type random(T a, T b) { return GeneratorWrapper<T>( - pf::make_unique<RandomIntegerGenerator<T>>(a, b) + std::make_unique<RandomIntegerGenerator<T>>(a, b) ); } @@ -77,7 +77,7 @@ typename std::enable_if<std::is_floating_point<T>::value, GeneratorWrapper<T>>::type random(T a, T b) { return GeneratorWrapper<T>( - pf::make_unique<RandomFloatingGenerator<T>>(a, b) + std::make_unique<RandomFloatingGenerator<T>>(a, b) ); } @@ -118,13 +118,13 @@ public: template <typename T> GeneratorWrapper<T> range(T const& start, T const& end, T const& step) { static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric"); - return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end, step)); + return GeneratorWrapper<T>(std::make_unique<RangeGenerator<T>>(start, end, step)); } template <typename T> GeneratorWrapper<T> range(T const& start, T const& end) { static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer"); - return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end)); + return GeneratorWrapper<T>(std::make_unique<RangeGenerator<T>>(start, end)); } @@ -158,13 +158,13 @@ template <typename InputIterator, typename InputSentinel, typename ResultType = typename std::iterator_traits<InputIterator>::value_type> GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) { - return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(from, to)); + return GeneratorWrapper<ResultType>(std::make_unique<IteratorGenerator<ResultType>>(from, to)); } template <typename Container, typename ResultType = typename Container::value_type> GeneratorWrapper<ResultType> from_range(Container const& cnt) { - return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end())); + return GeneratorWrapper<ResultType>(std::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end())); } diff --git a/src/catch2/catch_reporter_registrars.hpp b/src/catch2/catch_reporter_registrars.hpp index cbc4fb73..4aecd518 100644 --- a/src/catch2/catch_reporter_registrars.hpp +++ b/src/catch2/catch_reporter_registrars.hpp @@ -40,7 +40,7 @@ namespace Catch { class ListenerFactory : public IReporterFactory { IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr<T>( new T( config ) ); + return std::make_unique<T>(config); } std::string getDescription() const override { return std::string(); diff --git a/src/catch2/catch_stream.cpp b/src/catch2/catch_stream.cpp index 6c8e2828..23a43001 100644 --- a/src/catch2/catch_stream.cpp +++ b/src/catch2/catch_stream.cpp @@ -108,7 +108,7 @@ namespace Catch { mutable std::ostream m_os; public: DebugOutStream() - : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ), + : m_streamBuf( std::make_unique<StreamBufImpl<OutputDebugWriter>>() ), m_os( m_streamBuf.get() ) {} |