Boost logo

Boost Users :

Subject: [Boost-users] Fwd: Describing "traits" of a class's members
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2013-02-27 19:08:22


Hello,

A week ago I started a thread here called "Can boost help me
organize/parse lots of binary data?" As people started offering help,
it because clear I had no idea what I was trying to ask. I come back
with a clear question.

The attached file defines:

1. TCPosition: an object that describes a position

2. TCDoubleTraits: an object that describes characteristics of a
parameter represented as a double

3. TCUnsignedTraits: an object that describes characteristics of a
parameter that is represented as an unsigned

4. TCPositionTraits: a collection of TC*Traits plus some
boost::function magic to extract parameters from a TCPosition.

5. TCPositionTraits::PrintValues: a function that allows the user to
print all values of a TCPosition

The motivation for this round-about way of printing the parameters of
a "position" is that I have to deal with some objects that have lots
of parameters and I would like one central place where I define the
characteristics of the values and their order. In this example, that
place is TCPositionTraits. In my real life example I will want to
store traits such as the way the data is encoded and the way in which
the data needs to be transformed into "human readable" format.

Question:

Can you modify the attached program so that the object
TCPositionTraits holds all the traits for the TCPosition object. Not
just the traits for the "double" parameters, as is currently the case.
 Notably missing from TCPositionTraits is a reference to
TCPosition::mSteps.

Difficulty:

This is a difficult question to answer due to the fact that
TCPositionTraits has hard-coded in it the keyword "double". I cannot
figure out how to remove this.

Bonus:

Bonus points if your answer looks something like "yes it is possible
if you start using a boost concept which you apparently are not aware
of".

Note:

You'll need the C++11 brace-initialization capability to compile this.
 I used "g++ -std=c++0x test.cpp" with gcc 4.6.3.

Thank you,

Chris




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net