From 4ba249e947084bc74f748e8da54bfaa5f851dad7 Mon Sep 17 00:00:00 2001 From: Marius Bancila Date: Mon, 15 Jan 2018 10:40:19 +0200 Subject: [PATCH] make_uuid replaced with uuid_default_generator --- include/uuid.cpp | 2 +- include/uuid.h | 22 ++++++++++------------ test/test.cpp | 30 +++++++++++++++--------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/uuid.cpp b/include/uuid.cpp index ce32323..6b321ae 100644 --- a/include/uuid.cpp +++ b/include/uuid.cpp @@ -85,7 +85,7 @@ namespace uuids } } - uuid make_uuid() + uuid uuid_default_generator::operator()() { #ifdef _WIN32 diff --git a/include/uuid.h b/include/uuid.h index bb7a84a..3453c40 100644 --- a/include/uuid.h +++ b/include/uuid.h @@ -6,6 +6,7 @@ #include #include #include +#include namespace uuids { @@ -227,29 +228,26 @@ namespace uuids public: typedef uuid result_type; - uuid operator()() { return uuid{}; } + uuid operator()(); }; template - class uuid_random_generator + class basic_uuid_random_generator { public: typedef uuid result_type; - uuid_random_generator() {} - explicit uuid_random_generator(UniformRandomNumberGenerator& gen) {} - explicit uuid_random_generator(UniformRandomNumberGenerator* pGen) {} + basic_uuid_random_generator() {} + explicit basic_uuid_random_generator(UniformRandomNumberGenerator& gen) {} + explicit basic_uuid_random_generator(UniformRandomNumberGenerator* pGen) {} uuid operator()() { return uuid{}; } + + private: + }; - uuid make_uuid(); - - template - uuid make_uuid(Generator & g) - { - return g(); - } + using uuid_random_generator = basic_uuid_random_generator; } namespace std diff --git a/test/test.cpp b/test/test.cpp index 3aba201..9525eec 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -76,9 +76,9 @@ int main() } { - std::cout << "Test make" << std::endl; + std::cout << "Test default generator" << std::endl; - uuid const guid = uuids::make_uuid(); + uuid const guid = uuids::uuid_default_generator{}(); assert(!guid.nil()); assert(guid.size() == 16); assert(guid.version() == uuids::uuid_version::random_number_based); @@ -89,7 +89,7 @@ int main() std::cout << "Test equality" << std::endl; uuid empty; - uuid guid = uuids::make_uuid(); + uuid guid = uuids::uuid_default_generator{}(); assert(empty == empty); assert(guid == guid); @@ -100,16 +100,16 @@ int main() std::cout << "Test comparison" << std::endl; auto empty = uuid{}; - auto id = make_uuid(); + auto id = uuids::uuid_default_generator{}(); assert(empty < id); std::set ids{ uuid{}, - uuids::make_uuid(), - uuids::make_uuid(), - uuids::make_uuid(), - uuids::make_uuid() + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}() }; assert(ids.size() == 5); @@ -129,10 +129,10 @@ int main() std::unordered_set ids{ uuid{}, - uuids::make_uuid(), - uuids::make_uuid(), - uuids::make_uuid(), - uuids::make_uuid() + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}(), + uuids::uuid_default_generator{}() }; assert(ids.size() == 5); @@ -143,7 +143,7 @@ int main() std::cout << "Test swap" << std::endl; uuid empty; - uuid guid = uuids::make_uuid(); + uuid guid = uuids::uuid_default_generator{}(); assert(empty.nil()); assert(!guid.nil()); @@ -202,7 +202,7 @@ int main() constexpr uuid_version version = empty.version(); } - { + {/* auto id1 = make_uuid(); uuid_default_generator dgen; @@ -214,7 +214,7 @@ int main() uuid_random_generator rgen(mtgen); auto id4 = make_uuid(rgen); auto id5 = make_uuid(rgen); - } + */} std::cout << "ALL PASSED" << std::endl;