From: kwikius on

Walter Bright wrote:
> kwikius wrote:
> > A 2D 3D point or vector would be much more useful to me than complex
> > numbers and of course I would want both vectors and complex numbers to
> > work with my types, which I will bet the D version wont do.
>
> Why would you assume it won't? Do int's not work with your types?

Well to work with my quantity types you need a signature of

template <typename T1, typename T2>
typeof(T1() / T2()) operator / (complex<T1> const &, complex<T2>
const&)

etc

(If that is the signature of the D complex I apologise)

for example

typedef complex<quan::resistance::kR> impedance;
impedance z = complex<quan::voltage::mV>() /
complex<quan::current::mA>(1);

Recently also I have discovered the power of 'static types.

for example:

static_double<0> operator *(double const & , static_double<0>)
{
return static_double<0>();
}

which of course is easily resolved to a no-op by the compiler

In this case my complex would have two params:

template<typename Real, typename Imag>
struct complex;

for an imaginary type :
typedef static_<double,0> zero;
typedef complex<zero,double> imag;

Although an imaginary type would be superior.

For both C++ and D the real battle is comprehensive standard libraries
though IMO.

regards
Andy Little


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Nemanja Trifunovic on

>
> size_type find (charT c, size_type pos = 0) const;
>
> What if c isn't ASCII?
>
> Consider this snippet from the Standard:
>
> string s1("abc");
> string::iterator i = s1.begin();
> string s2 = s1;
> *i = 'a';
>
> How is that supposed to work, if 'a' is not ASCII?

But what woud you expect? The user simply must take the string encoding
into consideration when doing string operations like that. If s1
contains a string in some multibyte encoding the user must be aware of
it. This is not specific to utf-8.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Walter Bright on
kwikius wrote:
> Walter Bright wrote:
>> kwikius wrote:
>>> A 2D 3D point or vector would be much more useful to me than complex
>>> numbers and of course I would want both vectors and complex numbers to
>>> work with my types, which I will bet the D version wont do.
>> Why would you assume it won't? Do int's not work with your types?
>
> Well to work with my quantity types you need a signature of

So you're doing dimensional analysis with C++ templates? Yes, you can do
that with D, and there's at least one person doing so (Oskar Linde).

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: David Abrahams on
Walter Bright <walter(a)digitalmars-nospamm.com> writes:

> David Abrahams wrote:
>> But then, I've never insisted on the ability to redefine
>> syntax and tokens, and I don't even believe it's necessary in order to
>> achieve the kind of flexibility and power I'm describing.
>
> How would you do it, then?

Several features could come together to do the job: excellent
first-class constant folding and first-class code block/expression
types come to mind. Some Haskell-style composed operators might help,
but probably aren't strictly necessary.

BTW, string literals would be a builtin feature, there's no question
about *that*.

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Walter Bright on
Nemanja Trifunovic wrote:
> But what woud you expect? The user simply must take the string encoding
> into consideration when doing string operations like that. If s1
> contains a string in some multibyte encoding the user must be aware of
> it. This is not specific to utf-8.

If it supported utf-8, I would expect things like encoding and decoding
of utf-8 to work. std::string right now offers nothing for the utf-8 user.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]