Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofCD1 status.

297. const_mem_fun_t<>::argument_type should be const T*

Section: 22.10.10[logical.operations]Status:CD1Submitter: Martin SeborOpened: 2001-01-06Last modified: 2016-01-28

Priority:Not Prioritized

View all issues withCD1 status.

Discussion:

The class templatesconst_mem_fun_t in 20.5.8, p8 andconst_mem_fun1_tin 20.5.8, p9 derive fromunary_function<T*, S>, andbinary_function<T*,A, S>, respectively. Consequently, theirargument_type, andfirst_argument_typemembers, respectively, are both defined to beT* (non-const).However, their function call member operator takes aconst T*argument. It is my opinion thatargument_type should beconstT* instead, so that one can easily refer to it in generic code. Theexample below derived from existing code fails to compile due to thediscrepancy:

template <class T>
void foo (typename T::argument_type arg)   // #1
{
    typename T::result_type (T::*pf) (typenameT::argument_type)const =   // #2
        &T::operator();
}

struct X { /* ... */ };

int main ()
{
    const X x;
    foo<std::const_mem_fun_t<void, X>>(&x);  // #3
}

#1foo() takes a plain unqualifiedX* as an argument
#2 the type of the pointer is incompatible with the type of the memberfunction
#3 the address of a constant being passed to a function taking a non-constX*

Proposed resolution:

Replace the top portion of the definition of the class templateconst_mem_fun_t in 20.5.8, p8

template <class S, class T> class const_mem_fun_t
          : publicunary_function<T*, S> {

with

template <class S, class T> class const_mem_fun_t
          : publicunary_function<const T*, S> {

Also replace the top portion of the definition of the class templateconst_mem_fun1_t in 20.5.8, p9

template <class S, class T, class A> class const_mem_fun1_t
          : publicbinary_function<T*, A, S> {

with

template <class S, class T, class A> class const_mem_fun1_t
          : publicbinary_function<const T*, A, S> {

Rationale:

This is simply a contradiction: theargument_type typedef,and the argument type itself, are not the same.


[8]ページ先頭

©2009-2026 Movatter.jp