Visualizzazione dei risultati da 1 a 9 su 9

Hybrid View

  1. #1
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Credo che il massimo che si possa ottenere sia questo:
    codice:
    struct type_a {};
    struct type_b {};
    struct type_c {};
    struct type_d {};
    struct type_e {};
    
    
    auto number (type_a x) {
        return make_tuple(10, "ss"s);
    }
    
    auto number( type_b x) {
        return make_tuple("dd"s, 10);
    }
    
    template <class T>
    auto wrapper (T a) -> decltype(number(a)) {
        return number(a);
    }
    
    int main(int argc, char* argv[]) {
    
            auto t1 = wrapper(type_a{});
            auto t2 = wrapper(type_b{});
    
    }
    dove number è in overload. Ovviamente i tipi di t1 e t2 sono incompatibili tra loro. Se è questo quello che ti serve puoi sfruttare questo esempio, altrimenti quello che vorresti fare con la enum è impossibile.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826
    Quote Originariamente inviata da shodan Visualizza il messaggio
    Credo che il massimo che si possa ottenere sia questo:
    codice:
    struct type_a {};
    struct type_b {};
    struct type_c {};
    struct type_d {};
    struct type_e {};
    
    
    auto number (type_a x) {
        return make_tuple(10, "ss"s);
    }
    
    auto number( type_b x) {
        return make_tuple("dd"s, 10);
    }
    
    template <class T>
    auto wrapper (T a) -> decltype(number(a)) {
        return number(a);
    }
    
    int main(int argc, char* argv[]) {
    
            auto t1 = wrapper(type_a{});
            auto t2 = wrapper(type_b{});
    
    }
    dove number � in overload. Ovviamente i tipi di t1 e t2 sono incompatibili tra loro. Se � questo quello che ti serve puoi sfruttare questo esempio, altrimenti quello che vorresti fare con la enum � impossibile.
    grazieshodan

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.