Boost logo

Boost :

Subject: Re: [boost] [qvm] Terseness of syntax etc.
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2015-12-08 15:53:37

Phil, thank you for your feedback.

On Tue, Dec 8, 2015 at 8:25 AM, Phil Endecott <
spam_from_boost_dev_at_[hidden]> wrote:

> I find most of the identifiers too short. To give just a couple
> of examples: "transp" is used to mean "transpose". You save
> typing three letters, and get confusion with transparent,
> transport, etc. Then look at the names of some traits classes;
> elsewhere we have type_traits, allocator_traits, iterator_traits
> etc. all spelt out in full, but in qvm we have q_traits, v_traits
> and m_traits.

I agree that transp is perhaps too short. The q_, v_ and m_traits though
shouldn't be a problem since throughout the entire library q, v and m mean
the same thing.

> I had a quick think about how a struct with x,y,z members could
> be adapted. Am I right in thinking that it would be necessary to
> write accessors like this inside the traits specialisation:
> float ir(int i, xyz_vec const & v) {
> switch (i) {
> case 0: return v.x;
> case 1: return v.y;
> case 2: return v.z;
> }
> }

The ir/iw accessors are for dynamic indexing and are generally optional.
You use r and w for read and write access and in that case access to x, y
and z can be implemented as specializations. I know, short names. :)


struct float3 { float x,y,z; };

        template <class V> struct v_traits;
        template <> struct v_traits<re::float3>
            typedef float scalar_type;
            static int const dim=3;
            template <int I> static float r( float3 const & );
            template <int I> static float & w( float3 & );

        template <> float v_traits<re::float3>::r<0>( float3 const & a ) {
return a.x; }
        template <> float v_traits<re::float3>::r<1>( float3 const & a ) {
return a.y; }
        template <> float v_traits<re::float3>::r<2>( float3 const & a ) {
return a.z; }

        template <> float & v_traits<re::float3>::w<0>( float3 & a ) {
return a.x; }
        template <> float & v_traits<re::float3>::w<1>( float3 & a ) {
return a.y; }
        template <> float & v_traits<re::float3>::w<2>( float3 & a ) {
return a.z; }

I'm really not a fan of the old operator% and now operator, syntax.
> To me, (v,XY) looks like you're forming a row-vector with two elements.
> Is there a reason why these accessors can't be written with function
> syntax, i.e. XY(v) ? Or, for matrices, something like element<4,2>(m)
> rather than (m,A<4,2>) ?

There is (m,A42) actually which seems preferable to element<4,2>(m). There
is no good solution for swizzling, unfortunately. I ended up with comma
because it looks nice to my eye, in combination with the parentheses. I can
list several problems of choosing comma, much like I can for any other
choice. :)

Emil <>

Boost list run by bdawes at, gregod at, cpdaniel at, john at