remove util self-written make_unique and use C++14 stdlib make_uniqe

This commit is contained in:
Huyen Chau Nguyen 2016-10-14 16:11:49 +02:00 committed by Daniel J. H
parent ef1f14550f
commit d0c142b9c7
8 changed files with 20 additions and 71 deletions

View File

@ -16,7 +16,6 @@
#include "util/guidance/turn_lanes.hpp"
#include "engine/geospatial_query.hpp"
#include "util/make_unique.hpp"
#include "util/range_table.hpp"
#include "util/rectangle.hpp"
#include "util/simple_logger.hpp"
@ -252,7 +251,7 @@ class SharedDataFacade final : public BaseDataFacade
shared_memory, storage::SharedDataLayout::NAME_CHAR_LIST);
util::ShM<char, true>::vector names_char_list(
names_list_ptr, data_layout->num_entries[storage::SharedDataLayout::NAME_CHAR_LIST]);
m_name_table = util::make_unique<util::RangeTable<16, true>>(
m_name_table = std::make_unique<util::RangeTable<16, true>>(
name_offsets, name_blocks, static_cast<unsigned>(names_char_list.size()));
m_names_char_list = std::move(names_char_list);
@ -354,7 +353,7 @@ class SharedDataFacade final : public BaseDataFacade
util::ShM<IndexBlock, true>::vector bearing_blocks(
blocks_ptr, data_layout->num_entries[storage::SharedDataLayout::BEARING_BLOCKS]);
m_bearing_ranges_table = util::make_unique<util::RangeTable<16, true>>(
m_bearing_ranges_table = std::make_unique<util::RangeTable<16, true>>(
bearing_offsets, bearing_blocks, static_cast<unsigned>(m_bearing_values_table.size()));
auto entry_class_ptr = data_layout->GetBlockPtr<util::guidance::EntryClass>(

View File

@ -1,51 +0,0 @@
#ifndef MAKE_UNIQUE_H_
#define MAKE_UNIQUE_H_
#include <cstdlib>
#include <memory>
#include <type_traits>
namespace osrm
{
namespace util
{
// Implement make_unique according to N3656. Taken from libcxx's implementation
/// \brief Constructs a `new T()` with the given args and returns a
/// `unique_ptr<T>` which owns the object.
///
/// Example:
///
/// auto p = make_unique<int>();
/// auto p = make_unique<std::tuple<int, int>>(0, 1);
template <class T, class... Args>
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args &&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
/// \brief Constructs a `new T[n]` with the given args and returns a
/// `unique_ptr<T[]>` which owns the object.
///
/// \param n size of the new array.
///
/// Example:
///
/// auto p = make_unique<int[]>(2); // value-initializes the array with 0's.
template <class T>
typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
std::unique_ptr<T>>::type
make_unique(size_t n)
{
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]());
}
/// This function isn't used and is only here to provide better compile errors.
template <class T, class... Args>
typename std::enable_if<std::extent<T>::value != 0>::type make_unique(Args &&...) = delete;
}
}
#endif // MAKE_UNIQUE_H_

View File

@ -11,7 +11,6 @@
#include "extractor/raster_source.hpp"
#include "util/graph_loader.hpp"
#include "util/io.hpp"
#include "util/make_unique.hpp"
#include "util/name_table.hpp"
#include "util/range_table.hpp"
#include "util/simple_logger.hpp"
@ -51,6 +50,7 @@
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <memory>
namespace osrm
{
@ -125,7 +125,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment)
util::SimpleLogger().Write() << "Threads: " << number_of_threads;
ExtractionContainers extraction_containers;
auto extractor_callbacks = util::make_unique<ExtractorCallbacks>(extraction_containers);
auto extractor_callbacks = std::make_unique<ExtractorCallbacks>(extraction_containers);
const osmium::io::File input_file(config.input_path.string());
osmium::io::Reader reader(input_file);

View File

@ -10,7 +10,6 @@
#include "extractor/restriction_parser.hpp"
#include "util/exception.hpp"
#include "util/lua_util.hpp"
#include "util/make_unique.hpp"
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
@ -23,6 +22,7 @@
#include <tbb/parallel_for.h>
#include <sstream>
#include <memory>
namespace osrm
{
@ -247,7 +247,7 @@ LuaScriptingContext &LuaScriptingEnvironment::GetLuaContext()
auto &ref = script_contexts.local(initialized);
if (!initialized)
{
ref = util::make_unique<LuaScriptingContext>();
ref = std::make_unique<LuaScriptingContext>();
InitContext(*ref);
}
luabind::set_pcall_callback(&luaErrorCallback);

View File

@ -7,14 +7,15 @@
#include "engine/engine.hpp"
#include "engine/engine_config.hpp"
#include "engine/status.hpp"
#include "util/make_unique.hpp"
#include <memory>
namespace osrm
{
// Pimpl idiom
OSRM::OSRM(engine::EngineConfig &config) : engine_(util::make_unique<engine::Engine>(config)) {}
OSRM::OSRM(engine::EngineConfig &config) : engine_(std::make_unique<engine::Engine>(config)) {}
OSRM::~OSRM() = default;
OSRM::OSRM(OSRM &&) noexcept = default;
OSRM &OSRM::operator=(OSRM &&) noexcept = default;

View File

@ -9,7 +9,8 @@
#include "server/api/parsed_url.hpp"
#include "util/json_util.hpp"
#include "util/make_unique.hpp"
#include <memory>
namespace osrm
{
@ -17,12 +18,12 @@ namespace server
{
ServiceHandler::ServiceHandler(osrm::EngineConfig &config) : routing_machine(config)
{
service_map["route"] = util::make_unique<service::RouteService>(routing_machine);
service_map["table"] = util::make_unique<service::TableService>(routing_machine);
service_map["nearest"] = util::make_unique<service::NearestService>(routing_machine);
service_map["trip"] = util::make_unique<service::TripService>(routing_machine);
service_map["match"] = util::make_unique<service::MatchService>(routing_machine);
service_map["tile"] = util::make_unique<service::TileService>(routing_machine);
service_map["route"] = std::make_unique<service::RouteService>(routing_machine);
service_map["table"] = std::make_unique<service::TableService>(routing_machine);
service_map["nearest"] = std::make_unique<service::NearestService>(routing_machine);
service_map["trip"] = std::make_unique<service::TripService>(routing_machine);
service_map["match"] = std::make_unique<service::MatchService>(routing_machine);
service_map["tile"] = std::make_unique<service::TileService>(routing_machine);
}
engine::Status ServiceHandler::RunQuery(api::ParsedURL parsed_url,

View File

@ -4,7 +4,6 @@
#include "util/exception.hpp"
#include "util/fingerprint.hpp"
#include "util/graph_loader.hpp"
#include "util/make_unique.hpp"
#include "util/simple_logger.hpp"
#include "util/static_graph.hpp"
#include "util/typedefs.hpp"
@ -125,7 +124,7 @@ int main(int argc, char *argv[])
osrm::util::SimpleLogger().Write() << "Starting SCC graph traversal";
auto tarjan =
osrm::util::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
std::make_unique<osrm::extractor::TarjanSCC<osrm::tools::TarjanGraph>>(graph);
tarjan->Run();
osrm::util::SimpleLogger().Write() << "identified: " << tarjan->GetNumberOfComponents()
<< " many components";

View File

@ -1,5 +1,4 @@
#include "server/server.hpp"
#include "util/make_unique.hpp"
#include "util/simple_logger.hpp"
#include "util/version.hpp"
@ -25,6 +24,7 @@
#include <new>
#include <string>
#include <thread>
#include <memory>
#ifdef _WIN32
boost::function0<void> console_ctrl_function;
@ -318,7 +318,7 @@ int main(int argc, const char *argv[]) try
#endif
auto routing_server = server::Server::CreateServer(ip_address, ip_port, requested_thread_num);
auto service_handler = util::make_unique<server::ServiceHandler>(config);
auto service_handler = std::make_unique<server::ServiceHandler>(config);
routing_server->RegisterServiceHandler(std::move(service_handler));