Folgende Frage.
habe von der Boost.org Seite das Beispiel
Code:
#include <list>
#include <boost/any.hpp>
using boost::any_cast;
typedef std::list<boost::any> many;
void append_int(many & values, int value)
{
boost::any to_append = value;
values.push_back(to_append);
}
void append_string(many & values, const std::string & value)
{
values.push_back(value);
}
void append_char_ptr(many & values, const char * value)
{
values.push_back(value);
}
void append_any(many & values, const boost::any & value)
{
values.push_back(value);
}
void append_nothing(many & values)
{
values.push_back(boost::any());
}
bool is_empty(const boost::any & operand)
{
return operand.empty();
}
bool is_int(const boost::any & operand)
{
return operand.type() == typeid(int);
}
bool is_char_ptr(const boost::any & operand)
{
try
{
any_cast<const char *>(operand);
return true;
}
catch(const boost::bad_any_cast &)
{
return false;
}
}
bool is_string(const boost::any & operand)
{
return any_cast<std::string>(&operand);
}
void count_all(many & values, std::ostream & out)
{
out << "#empty == "
<< std::count_if(values.begin(), values.end(), is_empty) << std::endl;
out << "#int == "
<< std::count_if(values.begin(), values.end(), is_int) << std::endl;
out << "#const char * == "
<< std::count_if(values.begin(), values.end(), is_char_ptr) << std::endl;
out << "#string == "
<< std::count_if(values.begin(), values.end(), is_string) << std::endl;
}
kopiert...
nachdem ich oben noch zwei Zusätzliche Includes gemacht habe kompiliert er es jetzt auch...
nun die Frage...
ich wollte nun mit der Funktion
Code:
append_any(many & values, const boost::any & value)
einen beliebigen Wert hinzufügen...
nur hab ich keinen plan wie der Aufruf der Funktion sein soll
desweiteren
wo ist dieser
values -Wert zu finden??
wird dieser nur durch den Aufruf der Funktion erzeugt??
kann mir jemand einen Beispielaufruf einer Funktion zeigen, mit dem ein Wert zugewiesen wird?
merci UFOSWORLD
p.s. für was brauche ich diesen Code
Code:
struct property
{
property();
property(const std::string &, const boost::any &);
std::string name;
boost::any value;
};
typedef std::list<property> properties;
Code:
class consumer
{
public:
virtual void notify(const any &) = 0;
...
};
Lesezeichen