我很想 通过以下方式解决这个问题:
#include <iostream>
#include <set>
#include <iterator>
#include <array>
#include <tuple>
#include <type_traits>
int main()
{
const std::set<int> s{ 0, 1, 2, 3, 4, 5, 6, 7, 8 };
auto iter = s.find(5);
using IterType = decltype(iter);
// using `std::array` works fine!
const auto& [pv1, nxt1] = std::array<IterType, 2>{std::prev(iter), std::next(iter)};
std::cout <<"using std::array<IterType, 2> :"<< *pv1 << " " << *nxt1 << '\n'; // prints: 4 6
// using ` std::make_tuple` works fine!
const auto& [pv2, nxt2] …Run Code Online (Sandbox Code Playgroud) 我在比较班级。对于下面的代码
#include <string>
#include <set>
#include <tuple>
#include <cassert>
enum class e : bool
{
positive = true,
negetive = false
};
class A
{
public:
int a;
e e1 : 1;
friend bool operator==(const A&, const A&);
};
bool operator==(const A& lhs, const A& rhs) {
auto tie = [](const A& a1) {
return std::tie(a1.a, a1.e1);
};
auto x1 = tie(lhs);
auto x2 = tie(rhs);
return x1 == x2;
}
int main()
{
A a1;
a1.a = 10;
a1.e1 …Run Code Online (Sandbox Code Playgroud)