2010-01-01

conversion functionの謎

template < typename T >
void f(T x)
{
    x = 1 ;// Error at VC
} ;

int main()
{
    int x = 0 ;
    f(std::ref(x)) ;
}

あれ? これってVCだけかな。

規格を読んだが、どうもこのコードが通るような記述は載っていない。ということは、エラーが正しいのか。

ということはだ、C++0xのstd::refって、使えないんじゃないか。関数オブジェクト限定か?

1 comment:

  1. GCC 4.4.2でもerrorでした。

    g++ -std=c++0x ref_test.cpp
    ref_test.cpp: In function ‘void f(Type) [with Type = std::reference_wrapper]’:
    ref_test.cpp:23: instantiated from here
    ref_test.cpp:13: error: no match for ‘operator=’ in ‘x = 1’
    /usr/include/c++/4.3/tr1_impl/functional:452: note: candidates are: std::reference_wrapper<_Tp>& std::reference_wrapper<_Tp>::operator=(const std::reference_wrapper<_Tp>&) [with _Tp = int]

    ReplyDelete

You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.