zoukankan      html  css  js  c++  java
  • boost用法

     1 #include <boost/variant.hpp>
     2 #include <boost/any.hpp>
     3 #include <vector>
     4 #include <string>
     5 #include <iostream>
     6 
     7 std::vector<boost::any> vector;
     8 
     9 struct output :
    10   public boost::static_visitor<>
    11 {
    12   void operator()(double &d) const
    13   {
    14     vector.push_back(d);
    15     std::cout << "double: " << d << std::endl;
    16   }
    17 
    18   void operator()(char &c) const
    19   {
    20     vector.push_back(c);
    21    std::cout << "char: " << c << std::endl;
    22   }
    23 
    24   void operator()(std::string &s) const
    25   {
    26     vector.push_back(s);
    27     std::cout << "string: " << s << std::endl;
    28   }
    29 };
    30 
    31 int main()
    32 {
    33   boost::variant<double, char, std::string> v;
    34   v = 3.14;
    35   boost::apply_visitor(output(), v);
    36   v = 'A';
    37   boost::apply_visitor(output(), v);
    38   v = "Hello, world!";
    39   boost::apply_visitor(output(), v);
    40 }

    http://zh.highscore.de/cpp/boost/datastructures.html 

  • 相关阅读:
    【POJ 2778】DNA Sequence
    【POJ 2923】Relocation
    codeforces 475D
    hdu4742
    hdu4741
    hdu5016
    poj3929
    Codeforces Round #267 (Div. 2)
    codeforces 455E
    hdu4073 Lights
  • 原文地址:https://www.cnblogs.com/sunbines/p/15209321.html
Copyright © 2011-2022 走看看