mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 07:27:23 +01:00
enh(Any): modernised source code.
This commit is contained in:
parent
bc8704f44e
commit
5c572fcdbd
@ -78,7 +78,7 @@ public:
|
|||||||
|
|
||||||
#ifndef POCO_NO_SOO
|
#ifndef POCO_NO_SOO
|
||||||
|
|
||||||
Placeholder(): pHolder(0)
|
Placeholder(): pHolder(nullptr)
|
||||||
{
|
{
|
||||||
std::memset(holder, 0, sizeof(holder));
|
std::memset(holder, 0, sizeof(holder));
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename V,
|
template<typename T, typename V,
|
||||||
typename std::enable_if<TypeSizeLE<T, Placeholder::Size::value>::value>::type* = nullptr>
|
typename std::enable_if_t<TypeSizeLE<T, Placeholder::Size::value>::value>* = nullptr>
|
||||||
PlaceholderT* assign(const V& value)
|
PlaceholderT* assign(const V& value)
|
||||||
{
|
{
|
||||||
erase();
|
erase();
|
||||||
@ -121,7 +121,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename V,
|
template<typename T, typename V,
|
||||||
typename std::enable_if<TypeSizeGT<T, Placeholder::Size::value>::value>::type* = nullptr>
|
typename std::enable_if_t<TypeSizeGT<T, Placeholder::Size::value>::value>* = nullptr>
|
||||||
PlaceholderT* assign(const V& value)
|
PlaceholderT* assign(const V& value)
|
||||||
{
|
{
|
||||||
erase();
|
erase();
|
||||||
@ -139,7 +139,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::max_align_t AlignerType;
|
using AlignerType = std::max_align_t;
|
||||||
static_assert(sizeof(AlignerType) <= SizeV + 1, "Aligner type is bigger than the actual storage, so SizeV should be made bigger otherwise you simply waste unused memory.");
|
static_assert(sizeof(AlignerType) <= SizeV + 1, "Aligner type is bigger than the actual storage, so SizeV should be made bigger otherwise you simply waste unused memory.");
|
||||||
|
|
||||||
void setLocal(bool local) const
|
void setLocal(bool local) const
|
||||||
@ -172,7 +172,7 @@ private:
|
|||||||
|
|
||||||
#else // POCO_NO_SOO
|
#else // POCO_NO_SOO
|
||||||
|
|
||||||
Placeholder(): pHolder(0)
|
Placeholder(): pHolder(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,12 +189,12 @@ private:
|
|||||||
void erase()
|
void erase()
|
||||||
{
|
{
|
||||||
delete pHolder;
|
delete pHolder;
|
||||||
pHolder = 0;
|
pHolder = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEmpty() const
|
bool isEmpty() const
|
||||||
{
|
{
|
||||||
return 0 == pHolder;
|
return nullptr == pHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isLocal() const
|
bool isLocal() const
|
||||||
@ -232,10 +232,8 @@ class Any
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Any()
|
Any() = default;
|
||||||
/// Creates an empty any type.
|
/// Creates an empty any type.
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ValueType>
|
template<typename ValueType>
|
||||||
Any(const ValueType & value)
|
Any(const ValueType & value)
|
||||||
@ -255,11 +253,9 @@ public:
|
|||||||
construct(other);
|
construct(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Any()
|
~Any() = default;
|
||||||
/// Destructor. If Any is locally held, calls ValueHolder destructor;
|
/// Destructor. If Any is locally held, calls ValueHolder destructor;
|
||||||
/// otherwise, deletes the placeholder from the heap.
|
/// otherwise, deletes the placeholder from the heap.
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Any& swap(Any& other) noexcept
|
Any& swap(Any& other) noexcept
|
||||||
/// Swaps the content of the two Anys.
|
/// Swaps the content of the two Anys.
|
||||||
@ -354,21 +350,19 @@ private:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const std::type_info& type() const
|
Holder & operator = (const Holder &) = delete;
|
||||||
|
|
||||||
|
const std::type_info& type() const override
|
||||||
{
|
{
|
||||||
return typeid(ValueType);
|
return typeid(ValueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void clone(Placeholder<ValueHolder>* pPlaceholder) const
|
void clone(Placeholder<ValueHolder>* pPlaceholder) const override
|
||||||
{
|
{
|
||||||
pPlaceholder->assign<Holder<ValueType>, ValueType>(_held);
|
pPlaceholder->assign<Holder<ValueType>, ValueType>(_held);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType _held;
|
ValueType _held;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Holder & operator = (const Holder &);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ValueHolder* content() const
|
ValueHolder* content() const
|
||||||
|
@ -369,10 +369,10 @@ namespace Impl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using EnableSigned = typename std::enable_if< std::is_signed<T>::value >::type*;
|
using EnableSigned = typename std::enable_if_t< std::is_signed<T>::value >*;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using EnableUnsigned = typename std::enable_if< std::is_unsigned<T>::value >::type*;
|
using EnableUnsigned = typename std::enable_if_t< std::is_unsigned<T>::value >*;
|
||||||
|
|
||||||
} // namespace Impl
|
} // namespace Impl
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user