I l@ve RuBoard Previous Section Next Section

Item 3. Case-Insensitive Strings桺art 2

Difficulty: 5

How usable is the ci_string we created in Item 2? Now we'll focus on usability issues, see what design problems or tradeoffs we encounter, and fill in some of the remaining gaps.

Consider again the solution for Item 2 (ignoring the function bodies):



struct ci_char_traits : public char_traits<char> 


{


  static bool eq( char c1, char c2 )   { /*...*/ }


  static bool lt( char c1, char c2 )   { /*...*/ }


  static int compare( const char* s1,


                      const char* s2,


                      size_t n )       { /*...*/ }


  static const char*


  find( const char* s, int n, char a ) { /*...*/ }


};


For this Item, answer the following related questions as completely as possible:

  1. Is it safe to inherit ci_char_traits from char_traits<char> this way?

  2. Why does the following code fail to compile?

    
    
    ci_string s = "abc"; 
    
    
    cout << s << endl;
    
    
    
  3. What about using other operators (for example, +, +=, =) and mixing strings and ci_strings as arguments? For example:

    
    
    string    a = "aaa"; 
    
    
    ci_string b = "bbb";
    
    
    string    c = a + b;
    
    
    
    I l@ve RuBoard Previous Section Next Section