user-defined operators in C++ -


what think imaginary possibility specify user-defined operators in c++.

such user-defined operator defined operator name (arbitrary sequence of allowed chars?), precedence, associativity , arity (something else?).

they used many purposes: build "tiny" dsls on c++, list comprehension etc.

wouldn't feature extend language possible usage? other languages allow user-defined operators? lisp comes mind, else? links topic?

well, haskell has custom operators settable precedence , left-right binding. so, can work. then, haskell cutting edge , barely readable is, though it's used rather clever people. (haskell scares off newbies, think..)

for c++, think there are:

  • parsing issues (consider std::vector<std::list<int>> bug, >> parsed right-shift operator) .. c++'s syntax hard enough is.
  • backwards-compability issues (introducing new operators combinations of old, !-- cause problems)
  • clarity issues (people doing enough wierd thing regular operators, making behaviour of program difficult enough divine is.)

the latter 1 dealbreaker, imo.

nevertheless, nothing stopping writing c++-preprocessor/parser replaces own-defined operators real function calls , uses normal c++ compiler (like how c++ built on c previously). neat experiment, if you'd keep sanity long enough ship. ;-)


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -