|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63311 - sandbox/variadic_templates/boost/composite_storage/alignment
From: cppljevans_at_[hidden]
Date: 2010-06-25 12:43:02
Author: cppljevans
Date: 2010-06-25 12:43:01 EDT (Fri, 25 Jun 2010)
New Revision: 63311
URL: http://svn.boost.org/trac/boost/changeset/63311
Log:
alignment metaclasses
Added:
sandbox/variadic_templates/boost/composite_storage/alignment/
sandbox/variadic_templates/boost/composite_storage/alignment/aligned_offset.hpp (contents, props changed)
sandbox/variadic_templates/boost/composite_storage/alignment/compose.hpp (contents, props changed)
Added: sandbox/variadic_templates/boost/composite_storage/alignment/aligned_offset.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/alignment/aligned_offset.hpp 2010-06-25 12:43:01 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,51 @@
+//compile-time aligned offset.
+#ifndef BOOST_COMPOSITE_STORAGE_ALIGNMENT_ALIGNED_OFFSET_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_ALIGNMENT_ALIGNED_OFFSET_HPP_INCLUDED
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace alignment
+{
+
+ template
+ < std::size_t Offset //minimum offset from start of some composite, C,
+ , std::size_t Alignment//for a component, Ci, whose alignment is Alignment.
+ >
+ struct
+aligned_offset
+{
+ static
+ std::size_t const
+ remainder
+ = Offset%Alignment
+ ;
+ static
+ std::size_t const
+ value
+ = remainder == 0
+ ? Offset
+ : Offset+(Alignment-remainder)
+ /**@brief
+ * value is minimum value > Offset such that
+ * value%Alignment == 0.
+ *
+ *Why is this useful?
+ * If:
+ * 1) the composite, C, is located in memory at Offset0
+ * and:
+ * 2) Offset0%Alignment == 0,
+ * then:
+ * (Offset0+value)%Alignment == 0,
+ * IOW, Ci will have the required alignment, Alignment.
+ *
+ */
+ ;
+
+};
+
+}//exit alignment namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
Added: sandbox/variadic_templates/boost/composite_storage/alignment/compose.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/alignment/compose.hpp 2010-06-25 12:43:01 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,73 @@
+//compile-time composition of alignments
+#ifndef BOOST_COMPOSITE_STORAGE_ALIGNMENT_COMPOSE_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_ALIGNMENT_COMPOSE_HPP_INCLUDED
+
+#ifdef COMPOSE_ALIGNMENTS_WITH_LCM
+ #include <boost/math/common_factor_ct.hpp>
+#endif
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace alignment
+{
+ template
+ < std::size_t Left
+ , std::size_t Right
+ >
+ struct
+compose
+/**@brief
+ * "Metafunction" returning alignment which is compatible with the
+ * metafunction argument alignments, Left and Right.
+ *
+ * The real reason why this template was created instead of directly using
+ * static_lcm was to provide the documentation shown below which justifies
+ * static_lcm use.
+ */
+{
+ static
+ std::size_t const
+ value=
+ #ifdef COMPOSE_ALIGNMENTS_WITH_LCM
+ ::boost::math::static_lcm
+ < (unsigned long)Left
+ , (unsigned long)Right
+ >::value
+ //The use of static_lcm is based on the statement:
+ //
+ // N is the least common multiple of all Alignments
+ //
+ //in paragraph 1 on page 10 of:
+ //
+ // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2165.pdf
+ //
+ //AFAICT, the reason lcm is used instead of just taking the
+ //maximum:
+ //
+ // Left>Right?Left:Right
+ //
+ //is to account for "Extended alignments" mentioned in paragraph 3
+ //on page 3 of the n2165 reference mentioned above. OTOH, if only
+ //"Fundamental alignments" are used (which, I assume, are the
+ //"static alignments;powers of 2" in paragraph 4 on page 5 of:
+ //
+ // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2140.pdf
+ //
+ //) then simply using max instead of lcm would work.
+ #else
+ Left>Right?Left:Right
+ //2010-03-11:
+ // this is what boost::variant does currently,
+ // although there's a pending fix:
+ // https://svn.boost.org/trac/boost/ticket/993
+ //
+ #endif
+ ;
+};
+
+}//exit alignment namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk