Skip to content

Запретить присвоение арифметические типы в std::string #425

Description

@apolukhin

Перенос предложения: голоса +??, -??
Автор идеи: ??

было бы хорошо если добавили эту:

//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64

#include <type_traits>

template< typename char_type>
   class basic_string
{    
  public:   
    basic_string& operator = (char c);
    
    template< typename T , class = typename std::enable_if< std::is_integral<T>::value && ! std::is_same<T, char_type>::value >::type >
    basic_string& operator = (T ) = delete;
};

typedef basic_string<char> string;
int main()
{
    string s;
    s = 'a';
    
    s = 23; // error C2280: 'basic_string<char> &basic_string<char>::operator =<int,void>(T)': attempting to reference a deleted function
        //with
        //[
        //    T=int
        //]
      //(15): note: see declaration of 'basic_string<char>::operator ='
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions