Ignore:
Timestamp:
Apr 11, 2025, 1:23:39 AM (6 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.cfa

    r570e7ad rd03a386  
    1414//
    1515
     16#define _COMPILING_STRING_CFA_
     17
    1618#include "string.hfa"
    1719#include "string_res.hfa"
     
    4042}
    4143
    42 void ?{}( string & s, string c ) {  // c is a memcpy of the real src string
     44PBOOST void ?{}( string & s, string c ) {  // c is a memcpy of the real src string
    4345        (s.inner) { malloc() };
    4446        ?{}( *s.inner, *c.inner, COPY_VALUE );
     
    146148// Assignment
    147149
    148 string & ?=?( string & s, string c ) {
     150PBOOST string & ?=?( string & s, string c ) {
    149151        (*s.inner) = (*c.inner);
    150152        return s;
     
    326328}
    327329
    328 string ?+?( string s, string s2 ) {
     330PBOOST string ?+?( string s, string s2 ) {
    329331        string ret = s;
    330332        ret += s2;
     
    375377}
    376378
    377 string ?*?( string s, strmul_factor_t factor ) {
     379PBOOST string ?*?( string s, strmul_factor_t factor ) {
    378380        string ret = s;
    379381        ret *= factor;
Note: See TracChangeset for help on using the changeset viewer.