Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma region IntelliSense_Fix
- #ifdef __INTELLISENSE__
- #include <print>
- #include <string>
- #include <chrono>
- #endif
- #pragma endregion
- import std;
- template <typename T>
- concept SignedNumeric = std::signed_integral<T> || std::floating_point<T>;
- //template <typename T>
- //requires std::signed_integral<T> || std::floating_point<T>
- //template <SignedNumeric T>
- auto valore_assoluto(SignedNumeric auto n);
- int stima_ampiezza();
- void riga_divisoria(char simbolo, int lunghezza=stima_ampiezza());
- //template <typename T>
- //requires std::signed_integral<T> || std::floating_point<T>
- //template <SignedNumeric T>
- //T valore_assoluto(T n)
- auto valore_assoluto(SignedNumeric auto n)
- {
- return n >= 0 ? n : -n;
- }
- // Funzione generica per tutti i numeri con segno
- template <SignedNumeric T>
- void elabora(T n) { /* algoritmo standard */ }
- // Funzione super-ottimizzata SOLO per i numeri in virgola mobile
- template <std::floating_point T>
- void elabora(T n) { /* algoritmo ultra-veloce */ }
- //un overload NON puo' differire solo per il tipo restituito
- //double valore_assoluto(double n)
- //{
- // return n >= 0.0 ? (double)n : (double) - n;
- //}
- void print(int n, char simbolo='-') {
- std::string n_str = std::format("{}", n);
- std::string bordo = std::string(n_str.length(), simbolo);
- std::println("{}", bordo);
- std::println("{}", n);
- std::println("{}", bordo);
- }
- // Stampa di un contenitore: richiede un ciclo e un iteratore
- void print(const std::vector<int>& v, char simbolo='=') {
- std::string bordo = std::string(50, simbolo);
- std::println("\n\n{}\n{}", bordo, bordo);
- for (int n : v) {
- std::println("*{}*",n);
- }
- std::println("{}\n{}", bordo, bordo);
- }
- // API C sottostante
- void send_data_i(int d){};
- void send_data_f(float d){};
- void send_data_s(const char* d){};
- // Wrapper C++
- void send(int d) { send_data_i(d); }
- void send(float d) { send_data_f(d); }
- void send(const char* d) { send_data_s(d); }
- int stima_ampiezza() { return 60; }
- void riga_divisoria(char simbolo, int lunghezza)
- {
- std::println("{}", std::string(lunghezza, simbolo));
- return;
- }
- auto main() -> int
- {
- int x {};
- std::println("{}", valore_assoluto<double>(- 34.8));
- //std::println("{}", valore_assoluto<std::string>("paperino"));
- x = -5;
- std::println("{}", valore_assoluto(x));
- //print(23567);
- auto v = std::vector<int>({13,5757,123454,35,345});
- //print(v);
- }
Advertisement
Add Comment
Please, Sign In to add comment