Proxy objects...

Discussion in 'C++' started by barcaroller, Apr 19, 2008.

  1. barcaroller

    barcaroller Guest

    What are proxy objects used for in C++? Currently, the only use of proxy
    objects I know of is that one can write one-liner code such as:

    myobj.foo() (a,b) (c,d) (e,f) ;

    where myobj.foo() returns a proxy object with an overloaded operator()
    member function, which returns a reference to the proxy object itself. But
    writing one-liners cannot be reason enough to use proxy objects.
     
    barcaroller, Apr 19, 2008
    #1
    1. Advertising

  2. barcaroller

    Kai-Uwe Bux Guest

    barcaroller wrote:

    >
    > What are proxy objects used for in C++? Currently, the only use of proxy
    > objects I know of is that one can write one-liner code such as:
    >
    > myobj.foo() (a,b) (c,d) (e,f) ;
    >
    > where myobj.foo() returns a proxy object with an overloaded operator()
    > member function, which returns a reference to the proxy object itself.
    > But writing one-liners cannot be reason enough to use proxy objects.


    The following come to mind:

    a) Matrix classes which support [][] notation have an operator[] which
    returns a proxy.

    b) std::vector<bool> uses proxy objects instead of references (since those
    won't do the trick).

    c) String classes and the like might return proxy objects (e.g., for
    operator[]) instead of references in order to avoid/solve aliasing
    problems. This can be useful for COW and reference counted implementations.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Apr 19, 2008
    #2
    1. Advertising

  3. barcaroller

    James Kanze Guest

    On 19 avr, 18:18, "barcaroller" <> wrote:
    > What are proxy objects used for in C++? Currently, the only
    > use of proxy objects I know of is that one can write one-liner
    > code such as:


    > myobj.foo() (a,b) (c,d) (e,f) ;


    > where myobj.foo() returns a proxy object with an overloaded
    > operator() member function, which returns a reference to the
    > proxy object itself. But writing one-liners cannot be reason
    > enough to use proxy objects.


    The two most frequent reasons I know of are for context
    dependent implicit type conversions (where the proxy has a:
    template< typename T > Proxy::eek:perator T() const
    function), and for distinguishing between lvalue and rvalue
    accesses (where the proxy will have an implicit conversion to
    the target type for rvalue accesses, and an operator= which
    modifies the source, rather than the proxy, for lvalue
    accesses).

    I don't think I've ever seen a proxy used as you've described.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 19, 2008
    #3
  4. barcaroller

    barcaroller Guest

    "James Kanze" <> wrote in message
    news:...

    > I don't think I've ever seen a proxy used as you've described.


    boost::program_options

    Example:

    options_description desc("Allowed options");

    desc.add_options()
    ("help", "help message")
    ("level", value<int>(), "set level");
     
    barcaroller, Apr 19, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vidy5300
    Replies:
    0
    Views:
    903
    vidy5300
    Jun 7, 2004
  2. 7stud
    Replies:
    11
    Views:
    730
    Dennis Lee Bieber
    Mar 20, 2007
  3. Replies:
    0
    Views:
    1,661
  4. Karsten Wutzke
    Replies:
    1
    Views:
    910
    Steven Simpson
    Aug 20, 2007
  5. Klein Stéphane
    Replies:
    3
    Views:
    613
    Steve Holden
    Dec 20, 2009
Loading...

Share This Page