[boost::units] Best practices for implementing custom units and quantities
Hello community, I am working on a project which works with units such as scale intervals (cents, moria, etc.) depending on the temperament system used (24-EDO, 72-EDO, etc.). My implementation defines a namespace for each tuning system. Within the namespaces I define base units, units and a system, as well as conversion factors between the systems. The base dimension is defined in only one of the namespaces (corresponding to the tuning system which I consider "standard" which is the 1200 cents per octave system). 1. Does such an approach qualify as a good approach in general (leaving aside the musical aspects)? 2. Is it a good practice to place all these namespaces in boost::units (extend boost::units)? Or should I keep them within my own namespaces? Learning the answer to #2 is more interesting to me, even in the absence of an answer to #1. Best regards, Alexandru Onea
On 28/02/2021 6:01 am, Alexandru Onea wrote:
My implementation defines a namespace for each tuning system. Within the namespaces I define base units, units and a system, as well as conversion factors between the systems. The base dimension is defined in only one of the namespaces (corresponding to the tuning system which I consider "standard" which is the 1200 cents per octave system).
1. Does such an approach qualify as a good approach in general (leaving aside the musical aspects)?
If you're wanting to have conversions between the systems, yes (see the metric and cgs systems in Boost.Units for some examples of this). Otherwise you can have them as completely independent systems if you don't need to convert between them, or if the only conversions happen "manually" outside of Boost.Units.
2. Is it a good practice to place all these namespaces in boost::units (extend boost::units)? Or should I keep them within my own namespaces?
No, you should never add your own types to any boost namespaces, including boost::units.
participants (2)
-
Alexandru Onea
-
Gavin Lambert