Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2003
    Messaggi
    4,826

    [c++stl]unary_function

    ciao.
    Sto cercando di capire le unary_function:

    codice:
    template<typename T>
    	struct DeleteObject:
    	public unary_function<const T*, void> {
    		void operator()(const T* ptr) const
    		delete ptr;
    	}
    };
    ho trovato queste spiegazioni sul perchè derivare il functore da unary_function:
    Unary_function is an empty base class: it contains no member functions or member variables, but only type information. The only reason it exists is to make it more convenient to define types that are models of the concept Adaptable Unary Function. Specifically, any model of Adaptable Unary Function must define nested typedefs. Those typedefs are provided by the base class unary_function.
    quello che non ho capito è il concetto di "Adaptable" mentre ho capito cosa sono i nested type.

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Alcuni algoritmi STL richiedono che siano definiti alcuni typedef.
    unary_function provvede a fornire: result_type e argument_type.
    Se non derivi da unary_function devi essere tu a fornire questi typedef.
    Questo è il senso di Adaptable.
    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.

  3. #3
    Per inciso, credo che tutti gli algoritmi che richiedono unary_function solo per il result_type ne potranno fare a meno grazie all'aggiunta delle keyword auto e decltype nel nuovo standard.
    Amaro C++, il gusto pieno dell'undefined behavior.

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 © 2024 vBulletin Solutions, Inc. All rights reserved.