File: our_variant_hello_world.cpp

package info (click to toggle)
mapbox-variant 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,648 kB
  • sloc: cpp: 31,068; ansic: 959; python: 424; makefile: 145; objc: 59; sh: 36
file content (20 lines) | stat: -rw-r--r-- 373 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <mapbox/variant.hpp>

#include <stdexcept>

struct check
{
    template <typename T>
    void operator()(T const& val) const
    {
        if (val != 0) throw std::runtime_error("invalid");
    }
};

int main()
{
    typedef mapbox::util::variant<bool, int, double> variant_type;
    variant_type v(0);
    mapbox::util::apply_visitor(check(), v);
    return 0;
}