summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-03-31 12:44:56 +0100
committerJose Fonseca <jfonseca@vmware.com>2016-04-04 16:35:34 +0100
commit05d2a5807d9e98d19bee1992c1948aaf35fd0315 (patch)
tree18153929f9d0e7606f787a0e080b1c24b8933240
parent1f9e61da66b89bdb2abe1882ea3b246a4e46c830 (diff)
compat: Implement std::make_unique.
-rw-r--r--cli/cli_dump.cpp6
-rw-r--r--compat/cxx_compat.hpp17
2 files changed, 19 insertions, 4 deletions
diff --git a/cli/cli_dump.cpp b/cli/cli_dump.cpp
index 682ddf61..817095bb 100644
--- a/cli/cli_dump.cpp
+++ b/cli/cli_dump.cpp
@@ -37,7 +37,7 @@
#include <fstream>
#include <string>
-#include "cxx_compat.hpp" // for std::to_string
+#include "cxx_compat.hpp" // for std::to_string, std::make_unique
#include "cli.hpp"
#include "cli_pager.hpp"
@@ -224,9 +224,9 @@ command(int argc, char *argv[])
std::unique_ptr<trace::Dumper> dumper;
if (blobs) {
- dumper = std::unique_ptr<trace::Dumper>(new BlobDumper(std::cout, dumpFlags));
+ dumper = std::make_unique<BlobDumper>(std::cout, dumpFlags);
} else {
- dumper = std::unique_ptr<trace::Dumper>(new trace::Dumper(std::cout, dumpFlags));
+ dumper = std::make_unique<trace::Dumper>(std::cout, dumpFlags);
}
for (int i = optind; i < argc; ++i) {
diff --git a/compat/cxx_compat.hpp b/compat/cxx_compat.hpp
index 1f67fb17..37d41c40 100644
--- a/compat/cxx_compat.hpp
+++ b/compat/cxx_compat.hpp
@@ -31,7 +31,7 @@
/*
- * Emulate std::to_string on Android
+ * Emulate std::to_string on Android.
*
* XXX: There might be different solutions per
* http://stackoverflow.com/questions/26095886/error-to-string-is-not-a-member-of-std
@@ -48,3 +48,18 @@ namespace std {
}
}
#endif /* ANDROID */
+
+
+/*
+ * Implement std::make_unique on C++11.
+ */
+#if !defined(_MSC_VER) && __cplusplus < 201402L
+#include <memory>
+#include <utility>
+namespace std {
+ template< typename T, typename... Args >
+ unique_ptr<T> make_unique(Args&&... args) {
+ return unique_ptr<T>(new T(forward<Args>(args)...));
+ }
+}
+#endif