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

### 177. Complex operators cannot be explicitly instantiated

Section: 28.4.6 [complex.ops] Status: NAD Submitter: Judy Ward Opened: 1999-07-02 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [complex.ops].

View all issues with NAD status.

Discussion:

A user who tries to explicitly instantiate a complex non-member operator will get compilation errors. Below is a simplified example of the reason why. The problem is that iterator_traits cannot be instantiated on a non-pointer type like float, yet when the compiler is trying to decide which operator+ needs to be instantiated it must instantiate the declaration to figure out the first argument type of a reverse_iterator operator.

    namespace std {
    template <class Iterator>
    struct iterator_traits
    {
        typedef typename Iterator::value_type value_type;
    };

    template <class T> class reverse_iterator;

    // reverse_iterator operator+
    template <class T>
    reverse_iterator<T> operator+
    (typename iterator_traits<T>::difference_type, const reverse_iterator<T>&);

    template <class T> struct complex {};

    // complex operator +
    template <class T>
    complex<T> operator+ (const T& lhs, const complex<T>& rhs)
    { return complex<T>();}
    }

    // request for explicit instantiation
    template std::complex<float> std::operator+<float>(const float&,
         const std::complex<float>&);

See also c++-stdlib reflector messages: lib-6814, 6815, 6816.

Rationale:

Implementors can make minor changes and the example will work. Users are not affected in any case.

According to John Spicer, It is possible to explicitly instantiate these operators using different syntax: change "std::operator+<float>" to "std::operator+".

The proposed resolution of issue 120 is that users will not be able to explicitly instantiate standard library templates. If that resolution is accepted then library implementors will be the only ones that will be affected by this problem, and they must use the indicated syntax.