prevent vector/string/map range constructors to be used when the input arg is not a range (prevent conflicts with other ctors)

master
Daniel Kolesa 2015-06-15 19:43:54 +01:00
parent 7cdac42c4a
commit e15bb6adf3
3 changed files with 47 additions and 21 deletions

View File

@ -65,40 +65,47 @@ public:
using ConstRange = octa::HashRange<const octa::Pair<const K, T>>; using ConstRange = octa::HashRange<const octa::Pair<const K, T>>;
using Allocator = A; using Allocator = A;
explicit Map(octa::Size size, const H &hf = H(), const C &eqf = C(), explicit Map(octa::Size size, const H &hf = H(),
const A &alloc = A()): p_table(size, hf, eqf, alloc) {} const C &eqf = C(), const A &alloc = A()
): p_table(size, hf, eqf, alloc) {}
Map(): Map(octa::Size(1 << 10)) {} Map(): Map(octa::Size(1 << 10)) {}
explicit Map(const A &alloc): Map(octa::Size(1 << 10), H(), C(), alloc) {} 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 A &alloc): Map(size, H(), C(), alloc) {}
Map(octa::Size size, const H &hf, const A &alloc): Map(size, hf, C(), Map(octa::Size size, const H &hf, const A &alloc): Map(size, hf, C(), alloc) {}
alloc) {}
template<typename R> template<typename R>
Map(R range, octa::Size size = 1 << 10, const H &hf = H(), const C &eqf = C(), Map(R range, octa::Size size = 1 << 10, const H &hf = H(),
const A &alloc = A()): p_table(size, hf, eqf, alloc) { const C &eqf = C(), const A &alloc = A(),
octa::EnableIf<
octa::IsInputRange<R>::value &&
octa::IsConvertible<RangeReference<R>, Value>::value,
bool
> = true
): p_table(size, hf, eqf, alloc) {
for (; !range.empty(); range.pop_front()) for (; !range.empty(); range.pop_front())
emplace(range.front()); emplace(range.front());
} }
template<typename R> template<typename R>
Map(R range, octa::Size size, const A &alloc): Map(range, size, H(), C(), Map(R range, octa::Size size, const A &alloc)
alloc) {} : Map(range, size, H(), C(), alloc) {}
template<typename R> template<typename R>
Map(R range, octa::Size size, const H &hf, const A &alloc): Map(R range, octa::Size size, const H &hf, const A &alloc)
Map(range, size, hf, C(), alloc) {} : Map(range, size, hf, C(), alloc) {}
Map(octa::InitializerList<Value> init, octa::Size size = 1 << 10, Map(octa::InitializerList<Value> init, octa::Size size = 1 << 10,
const H &hf = H(), const C &eqf = C(), const A &alloc = A()): const H &hf = H(), const C &eqf = C(), const A &alloc = A()
Map(octa::each(init), size, hf, eqf, alloc) {} ): Map(octa::each(init), size, hf, eqf, alloc) {}
Map(octa::InitializerList<Value> init, octa::Size size, const A &alloc): Map(octa::InitializerList<Value> init, octa::Size size, const A &alloc)
Map(octa::each(init), size, H(), C(), alloc) {} : Map(octa::each(init), size, H(), C(), alloc) {}
Map(octa::InitializerList<Value> init, octa::Size size, const H &hf, Map(octa::InitializerList<Value> init, octa::Size size, const H &hf,
const A &alloc): Map(octa::each(init), size, hf, C(), alloc) {} const A &alloc
): Map(octa::each(init), size, hf, C(), alloc) {}
bool empty() const { return p_table.empty(); } bool empty() const { return p_table.empty(); }
octa::Size size() const { return p_table.size(); } octa::Size size() const { return p_table.size(); }

View File

@ -174,8 +174,13 @@ public:
StringBase(ConstPointer v, Size n, const A &a = A()): StringBase(ConstPointer v, Size n, const A &a = A()):
p_buf(ConstRange(v, n), a) {} p_buf(ConstRange(v, n), a) {}
template<typename R> StringBase(R range, const A &a = A()): template<typename R> StringBase(R range, const A &a = A(),
p_buf(range, a) { octa::EnableIf<
octa::IsInputRange<R>::value &&
octa::IsConvertible<RangeReference<R>, Value>::value,
bool
> = true
): p_buf(range, a) {
terminate(); terminate();
} }
@ -193,7 +198,12 @@ public:
p_buf = ConstRange(v, strlen(v) + 1); p_buf = ConstRange(v, strlen(v) + 1);
return *this; return *this;
} }
StringBase &operator=(const Range &r) { template<typename R>
octa::EnableIf<
octa::IsInputRange<R>::value &&
octa::IsConvertible<RangeReference<R>, Value>::value,
StringBase &
> operator=(const R &r) {
p_buf = r; p_buf = r;
terminate(); terminate();
return *this; return *this;

View File

@ -167,8 +167,13 @@ public:
Vector(InitializerList<T> v, const A &a = A()): Vector(InitializerList<T> v, const A &a = A()):
Vector(v.begin(), v.size(), a) {} Vector(v.begin(), v.size(), a) {}
template<typename R> Vector(R range, const A &a = A()): template<typename R> Vector(R range, const A &a = A(),
Vector(a) { octa::EnableIf<
octa::IsInputRange<R>::value &&
octa::IsConvertible<RangeReference<R>, Value>::value,
bool
> = true
): Vector(a) {
ctor_from_range(range); ctor_from_range(range);
} }
@ -224,7 +229,11 @@ public:
} }
template<typename R> template<typename R>
Vector &operator=(R range) { octa::EnableIf<
octa::IsInputRange<R>::value &&
octa::IsConvertible<RangeReference<R>, Value>::value,
Vector &
> operator=(R range) {
clear(); clear();
ctor_from_range(range); ctor_from_range(range);
return *this; return *this;