本文整理汇总了C++中variant::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::empty方法的具体用法?C++ variant::empty怎么用?C++ variant::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variant
的用法示例。
在下文中一共展示了variant::empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: swap
void variant::swap(variant &other) noexcept
{
using std::swap;
auto thisEmpty = this->empty();
auto otherEmpty = other.empty();
if (thisEmpty && otherEmpty)
return;
if (thisEmpty && !otherEmpty)
{
other.manager->f_move(other.storage, storage);
manager = other.manager;
other.manager = internal::variant_function_table_for<void>();
other.storage = storage_t{};
return;
}
if (!thisEmpty && otherEmpty)
{
manager->f_move(storage, other.storage);
other.manager = manager;
manager = internal::variant_function_table_for<void>();
storage = storage_t{};
return;
}
storage_t temporary;
manager->f_move(storage, temporary);
other.manager->f_move(other.storage, storage);
manager->f_move(temporary, other.storage);
swap(manager, other.manager);
}
示例2: write_element
void xml_writer_impl::write_element(const variant& element)
{
try
{
if (element.is<variant::Collection>() && element.empty() && element.type() != variant::DataTable)
{
write_empty_element();
return;
}
switch(element.type())
{
case variant::None:
{
write_empty_element();
break;
}
case variant::Any:
case variant::String:
{
if (element.as<std::string>().empty())
{
write_empty_element();
break;
}
}
case variant::Float:
case variant::Double:
case variant::Int32:
case variant::UInt32:
case variant::Int64:
case variant::UInt64:
case variant::Boolean:
case variant::Date:
case variant::Time:
case variant::DateTime:
{
m_os << start_tag();
write_text(element);
m_os << end_tag();
break;
}
case variant::Dictionary:
case variant::Bag:
{
if ((m_mode & xml_mode::Preserve)!=0)
{
if (element.has_key(xml_attributes))
{
m_stack.top().m_attributes = element[xml_attributes];
if (element.size()==1)
{
write_empty_element();
break;
}
}
m_os << start_tag();
bool prev_is_text = false;
variant::const_iterator it, end(element.end());
for (it=element.begin(); it!=end; ++it)
{
if (it.key()==xml_attributes)
{
continue;
}
else if (it.key()==xml_text)
{
write_text(it.value());
prev_is_text = true;
}
else if (it.key()==xml_instruction)
{
push(it.key());
if (!prev_is_text)
{
m_os << indent();
}
write_instruction(it.value());
prev_is_text = false;
pop();
}
else if (it.key()==xml_comment)
{
push(it.key());
if (!prev_is_text)
{
m_os << indent();
}
write_comment(it.value());
prev_is_text = false;
//.........这里部分代码省略.........