Page tree
Skip to end of metadata
Go to start of metadata

A list of FB::variants and associated helpers.

Introduction

FB::VariantList is a container of FB::variant. Its a random-access-container that supports access by index - currently simply a std::vector<FB::variant>.

To ease working with VariantList, a set of helper functions is provided.

variant_list_of()

Allows convenient creation of FB::VariantList, similar to Boost.Assign.

Related Types

FB::detail::VariantListInserter

  • contains a new FB::VariantList
  • supports insertion through operator()(const FB::variant&)
  • is convertible to FB::VariantList through operator FB::VariantList& ()

Versions

FB::detail::VariantListInserter FB::variant_list_of()

  • returns a new VariantListInserter

FB::detail::VariantListInserter FB::variant_list_of(const FB::variant& var)

  • returns a new VariantListInserter, containing a VariantList that contains var

Examples

FB::VariantList vars = FB::variant_list_of(1)("2")(3.4);

FireEvent("randomDiceRoll", FB::variant_list_of(4));

make_variant_list()

make_variant_list() allows you to create new {{FB::VariantList}}s from STL-style containers.

Versions

template<class Cont> FB::VariantList make_variant_list(const Cont& c)

  • Cont - a STL Forward Container, e.g. std::vector
  • returns a FB::VariantList filled with the contents of c

template<class InputIterator> FB::VariantList make_variant_list(InputIterator first, InputIterator last)

  • returns a FB::VariantList with the contents of the range [first, last)

template<class InputIterator> void make_variant_list(InputIterator first, InputIterator last, FB::VariantList::iterator result)

  • result - an iterator to the begin of a VariantList range big enough to hold last-first values
  • results in the range [result,result+(last-first)) being filled with the contents of the range [first, last)

Examples

int vals[] = {1,2,3,4,5};
std::vector<int> valVec(vals, vals+5);

FB::VariantList vars = FB::make_variant_list(valVec);
// vars contains 1,2,3,4,5 now

FB::VariantList vars2 = FB::make_variant_list(valVec.begin(), valVec.end()-1);
// vars2 now contains 1,2,3,4

FB::VariantList vars3(valVec.size());
FB::make_variant_list(valVec.begin(), valVec.end()-2, vars3.begin());
// vars3 now contains 1,2,3

convert_variant_list()

convert_variant_list() allows convenient conversion of FB::VariantList to STL-style containers.

Versions

template<class Cont> Cont convert_variant_list(const FB::VariantList& from)

  • Cont - a STL-style container to convert to
  • returns a Cont filled with the contents of from, converted to Cont::value_type

template<class Cont> Cont convert_variant_list(FB::VariantList::const_iterator first, FB::VariantList::const_iterator last)

  • Cont - a STL-style container to convert to
  • returns a Cont, filled with the contents of the range [first, last), converted to Cont::value_type

template<class Cont> void convert_variant_list(const FB::VariantList& from, Cont& to)

  • fills Cont with the contents of from, converted to Cont::value_type

template<class To, class OutputIterator> void convert_variant_list(FB::VariantList::const_iterator first, FB::VariantList::const_iterator last, OutputIterator result)

  • fills the range [result, result+(last-first)) with the contents of the range [first,last), converted to To

Examples

typedef std::vector<std::string> StringVec;
FB::VariantList vars = FB::variant_list_of(1)("2")(3.0);

StringVec strings1 = FB::convert_variant_list<StringVec>(vars);
StringVec strings2 = FB::convert_variant_list<StringVec>(vars.begin(), vars.end()-1);

StringVec strings3(vars.size());
FB::convert_variant_list(vars, strings3);

StringVec strings4(vars.size()-1);
FB::convert_variant_list<std::string>(vars.begin(), vars.end()-1, strings4.begin());
  • No labels