Ignore:
Timestamp:
Apr 11, 2025, 1:23:39 AM (9 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
dab6e39
Parents:
570e7ad
Message:

Give a few string operator overloads a preference boost.

Intent is to approximate: When selecting +/* candidates, treat it ambiguous until finding a user-given arithmetic-vs-string constraint, such as assigning the result to a string. Once a string interpretation is imposed, prefer an alternative that converts to string as soon as possible.

This description is not directly achievable with the CFA type system. The approximation has the known flaw shown in the string-operator test, where a fairly built-up expression that should be ambiguous is actually defaulting to the string version.

This change is the last of the string-overload reorganizations that the string-operator test was originally meant to illustrate. In Mike's opinion, the resulting state is ideal, except for the just-mentioned flaw.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/collections/string.hfa

    r570e7ad rd03a386  
    1919#include <string_res.hfa>
    2020
     21static struct __cfa_string_preference_boost_t {} __cfa_string_preference_boost;
     22#define PBOOST forall ( | { __cfa_string_preference_boost_t __cfa_string_preference_boost; } )
     23
    2124struct string {
    2225        string_res * inner;
     
    2831void ?{}( string & s );                                                                 // empty string
    2932void ?{}( string & s, string s2, size_t maxlen );
    30 void ?{}( string & s, string s2 );
     33PBOOST void ?{}( string & s, string s2 );
    3134void ?{}( string & s, char );
    3235void ?{}( string & s, const char * c );                                 // copy from string literal (NULL-terminated)
     
    4851// string str( long double _Complex rhs );
    4952
    50 string & ?=?( string & s, string c );
     53PBOOST string & ?=?( string & s, string c );
    5154string & ?=?( string & s, const char * c );                             // copy from "literal"
    5255string & ?=?( string & s, char c );                                             // copy from 'l'
     
    162165string ?+?( string s, char c );
    163166string ?+?( char c, string s );
    164 string ?+?( string s, string s2 );
     167PBOOST string ?+?( string s, string s2 );
    165168string ?+?( const char * s, char c );                                   // not backwards compatible
    166169string ?+?( char c, const char * s );
     
    184187void ?*=?( string & s, strmul_factor_t factor );
    185188string ?*?( char c, strmul_factor_t factor );                                   // not backwards compatible
    186 string ?*?( string s, strmul_factor_t factor );
     189PBOOST string ?*?( string s, strmul_factor_t factor );
    187190string ?*?( const char * s, strmul_factor_t factor );
    188191static inline string ?*?( strmul_factor_t factor, char s ) { return s * factor; }
    189 static inline string ?*?( strmul_factor_t factor, string s ) { return s * factor; }
     192PBOOST static inline string ?*?( strmul_factor_t factor, string s ) { return s * factor; }
    190193static inline string ?*?( strmul_factor_t factor, const char * s ) { return s * factor; }
    191194
     
    314317        return translate( S, f );
    315318}
     319
     320#ifndef _COMPILING_STRING_CFA_
     321#undef PBOOST
     322#endif
Note: See TracChangeset for help on using the changeset viewer.