From 13e553f85cf568a425071597da0876150b66c353 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 15 Jun 2015 02:22:10 +0100 Subject: [PATCH] hash initializer list and range ctors --- octa/map.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/octa/map.h b/octa/map.h index b99f30d..6ff7f4a 100644 --- a/octa/map.h +++ b/octa/map.h @@ -10,6 +10,7 @@ #include "octa/utility.h" #include "octa/memory.h" #include "octa/functional.h" +#include "octa/initializer_list.h" #include "octa/internal/hashtable.h" @@ -67,13 +68,38 @@ public: explicit Map(octa::Size size, const H &hf = H(), const C &eqf = C(), const A &alloc = A()): p_table(size, hf, eqf, alloc) {} - Map(): Map(1 << 10) {} - explicit Map(const A &alloc): Map(1 << 10, H(), C(), alloc) {} + Map(): Map(octa::Size(1 << 10)) {} + explicit Map(const A &alloc): Map(octa::Size(1 << 10), H(), C(), alloc) {} Map(octa::Size size, const A &alloc): Map(size, H(), C(), alloc) {} Map(octa::Size size, const H &hf, const A &alloc): Map(size, hf, C(), alloc) {} + template + Map(R range, octa::Size size = 1 << 10, const H &hf = H(), const C &eqf = C(), + const A &alloc = A()): p_table(size, hf, eqf, alloc) { + for (; !range.empty(); range.pop_front()) + emplace(range.front()); + } + + template + Map(R range, octa::Size size, const A &alloc): Map(range, size, H(), C(), + alloc) {} + + template + Map(R range, octa::Size size, const H &hf, const A &alloc): + Map(range, size, hf, C(), alloc) {} + + Map(octa::InitializerList init, octa::Size size = 1 << 10, + const H &hf = H(), const C &eqf = C(), const A &alloc = A()): + Map(octa::each(init), size, hf, eqf, alloc) {} + + Map(octa::InitializerList init, octa::Size size, const A &alloc): + Map(octa::each(init), size, H(), C(), alloc) {} + + Map(octa::InitializerList init, octa::Size size, const H &hf, + const A &alloc): Map(octa::each(init), size, hf, C(), alloc) {} + bool empty() const { return p_table.empty(); } octa::Size size() const { return p_table.size(); } octa::Size max_size() const { return p_table.max_size(); }