Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <concepts>
- #include <format>
- using namespace std;
- template <typename T>
- concept Number = integral<T> || floating_point<T>;
- template <typename T1, typename T2>
- concept Number2 = integral<T1> && floating_point<T2>;
- template <typename T1, typename T2>
- requires Number2<T1, T2>
- T1 somma2(T1 a, T2 b) {
- return a + b;
- }
- template <typename T>
- T somma(T a, T b) requires Number<T> {
- return a + b;
- }
- struct Punto3D {
- int x = 0;
- int y = 0;
- int z = 0;
- };
- struct Punto2D {
- int x = 0;
- int y = 0;
- Punto2D operator +(Punto3D &altro) const
- {
- return Punto2D{x+altro.x, y+altro.y};
- }
- };
- int main()
- {
- Punto2D p1 { 5, 10 };
- Punto3D p2{ 4, -9, 12 };
- /*auto p3 = somma2<Punto2D, Punto3D>(p1, p2);
- cout << format("Punto risultato: ({},{})\n", p3.x, p3.y);*/
- cout << somma<int>(5, 3) << endl;
- cout << somma<double>(3.15, 56) << endl;
- //cout << somma2<int>(5, 3) << endl;
- //cout << somma2<double>(3.15, 56) << endl;
- //cout << somma2<double>(56, 3.15) << endl;
- cout << somma2(56, 3.15) << endl;
- cout << somma2<int>(56, 3.15) << endl;
- cout << somma2<int, double>(56, 3.15) << endl;
- //cout << somma<string>("ciao", " a tutti") << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement