http://en.cppreference.com/w/cpp/utility/tuple/make_tuple (爲了方便代碼粘貼)C++ 11:boost :: make_tuple與std :: make_tuple有什麼不同?
#include <iostream>
#include <tuple>
#include <functional>
std::tuple<int, int> f() // this function returns multiple values
{
int x = 5;
return std::make_tuple(x, 7); // return {x,7}; in C++17
}
int main()
{
// heterogeneous tuple construction
int n = 1;
auto t = std::make_tuple(10, "Test", 3.14, std::ref(n), n);
n = 7;
std::cout << "The value of t is " << "("
<< std::get<0>(t) << ", " << std::get<1>(t) << ", "
<< std::get<2>(t) << ", " << std::get<3>(t) << ", "
<< std::get<4>(t) << ")\n";
// function returning multiple values
int a, b;
std::tie(a, b) = f();
std::cout << a << " " << b << "\n";
}
https://theboostcpplibraries.com/boost.tuple
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
#include <string>
#include <iostream>
int main()
{
typedef boost::tuple<std::string, int, bool> animal;
animal a = boost::make_tuple("cat", 4, true);
a.get<0>() = "dog";
std::cout << std::boolalpha << a << '\n';
}
這似乎是基於增強的文檔:: make_tuple和std :: make_tuple上是完全可以互換的。
它們真的可以互換嗎?他們在什麼情況下不是?
在升壓文檔上面說的boost ::元組和std ::元組是在C++ 11
在STD文檔一樣,它說make_tuple返回一個std ::元組。
那麼有沒有我失蹤的細微差別?
我認爲C++ 11幾乎只採用了boost :: tuple。所以他們會一樣也不奇怪。 –