monotone

monotone Mtn Source Tree

Root/vocab_cast.hh

1#ifndef __VOCAB_CAST_HH
2#define __VOCAB_CAST_HH
3
4#include <algorithm>
5
6// You probably won't use this yourself, but it's needed by...
7template<typename From, typename To>
8To typecast_vocab(From const & from)
9{ return To(from()); }
10
11// There are a few places where we want to typecast an entire
12// container full of vocab types.
13template<typename From, typename To>
14void typecast_vocab_container(From const & from, To & to)
15{
16 std::transform(from.begin(), from.end(), std::inserter(to, to.end()),
17 &typecast_vocab<typename From::value_type,
18 typename To::value_type>);
19}
20
21// You won't use this directly either.
22template<typename From, typename To>
23To add_decoration(From const & from)
24{
25 return To(from);
26}
27
28// There are also some places that want to decorate a container full
29// of vocab types.
30template<typename From, typename To>
31void add_decoration_to_container(From const & from, To & to)
32{
33 std::transform(from.begin(), from.end(), std::inserter(to, to.end()),
34 &add_decoration<typename From::value_type,
35 typename To::value_type>);
36}
37
38template<typename From, typename To>
39void vocabify_container(From const & from, To & to)
40{
41 add_decoration_to_container(from, to);
42}
43
44#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status