Mam problem z napisanie deklaracji przyjazni. W nastepujacym kodzie
#include <iostream>
#include <bitset>
#include <stdlib.h>
#include <windows.h>
#include <thread>
#include <algorithm>
#include <chrono>
#include <fstream>
#include <tuple>
#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <conio.h>
using namespace std;
template<typename T>
struct temp;
template<size_t nr, typename T>
T get(temp<T>);
template <typename T>
struct temp {
private:
T tab[3];
public:
temp(int a, int b, int c) :tab{ a,b,c } {
}
void show() {
for (auto i : tab)
cout << i << " ";
cout << endl;
}
template <size_t size>
friend T get<>(temp<T>);
};
template<size_t nr, typename T>
T get(temp<T> t) {
return t.tab[nr];
}
template <typename T>
struct std::tuple_size<temp<T>> {
const static size_t value = 3;
};
template <typename T,size_t nr>
struct std::tuple_element<nr,temp<T>> {
using type = int;
};
int main()
{
temp<int> t( 1,2,3 );
auto [a, b, c] = t;
cout << a << " " << b << " " << c << endl;
}
Probowalem na wszelkie sposoby lecz nie moge skompilowac tego kodu. Problem niby mozna rozwiazac zastepujac
template <size_t size>
friend T get<>(temp<T>);
Na
friend T get<0>(temp<T>);
friend T get<1>(temp<T>);
friend T get<2>(temp<T>);
Jednak nie moge znalezc uniwersalnego rozwiazania. Niby mozna takze zastapic ja taka definicja
template <size_t size,typename T>
friend T get<size,T>(temp<T>&);
Ale wtedy to relacja 1:n a mi zalezy na relacji 1:1