I can't understand why the code behaves this way?
#include <iostream>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/container/vector/vector_fwd.hpp>
#include <boost/fusion/include/vector_fwd.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/fusion/sequence/io.hpp>
#include <boost/fusion/include/io.hpp>
template<typename Ar>
v开发者_StackOverflow中文版oid func(Ar& ar, const boost::fusion::vector<>& v) {
std::cout << v << std::endl;
}
template<typename Ar, typename T0, typename T1>
void func(Ar& ar, const boost::fusion::vector<T0, T1>& v) {
std::cout << v << std::endl;
}
struct type {
template<typename T>
type& operator& (const T& v) {
func(*this, v);
return *this;
}
};
int main() {
type t;
t & boost::fusion::make_vector(33,44); // 1. <<<<<<<<<<<<<<<<<<<<<<<<
boost::fusion::vector<int, int> v(55,66); // 2.
t & v;
}
test code here
The question is, why in the first case the func() for an empty vector is called?
Documentation on this topic:
boost::fusion::vector
boost::fusion::make_vector()
Thank's.
This is roughly what I understand...
boost::fusion::make_vector()
from your usage of boost::fusion::make_vector(33,44)
returns a boost::fusion::vector2<int, int>
type and NOT a boost::fusion::vector<int, int, T2, T3,...>
(variadic) type. boost::fusion::vectorN
types can however convert itself to boost::fusion::vector<>
(variadic) type.
The first function accepts a variadic vector with NO type. Hence no elements are displayed. The second version accepts a variadic type with two template types declared, however since the first one matches better (because the default template types kick in) it gets choosen over the second one, when you use boost::fusion::make_vector
. When you define the type of the vector as in the second case, it has strong type specified and hence matches the second function and displays two elements of type int and int.
精彩评论