lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] reusing mc_enum<> for serialization into XML


From: Greg Chicares
Subject: Re: [lmi] reusing mc_enum<> for serialization into XML
Date: Thu, 25 Feb 2010 19:21:13 +0000
User-agent: Thunderbird 2.0.0.23 (Windows/20090812)

On 2010-02-25 08:04Z, Vaclav Slavik wrote:
> On Wed, 2010-02-24 at 19:18 +0000, Greg Chicares wrote:
>> However, do you feel that such assertions are valuable as documentation?
> 
> They were intended to be that. I hoped that should some metadata
> specialization be incorrect, they would present more understandable
> error.

Your other changes already improved the error messages considerably.
With this patch that introduces a deliberate error...

Index: mc_enum_test_aux.cpp
===================================================================
--- mc_enum_test_aux.cpp        (revision 4776)
+++ mc_enum_test_aux.cpp        (working copy)
@@ -42,7 +42,7 @@
 extern char const*const holiday_strings[] =
     {"Theophany"
     ,"Easter"
-    ,"Pentecost"
+//    ,"Pentecost"
     };
 template class mc_enum<enum_holiday>;

...prior to revision 4776, gcc said:
  error: could not convert template argument `holiday_strings' to `const char* 
const (&)[3]'
and como said:
  "\lmi/src/lmi/mc_enum_test_aux.cpp", line 47: error #459: initialization
          requiring a temporary or conversion is not allowed
  template class mc_enum<enum_holiday, 3, holiday_enums, holiday_strings>;
                                                         ^

...but, since revision 4776, messages are clearer--gcc says:
  mc_enum_test_aux.hpp:34: error: conflicting declaration 'const char* const 
holiday_strings[3]'
  mc_enum_test_aux.cpp:42: error: 'holiday_strings' has a previous declaration 
as `const char* const holiday_strings[2]'
  mc_enum_test_aux.hpp:34: error: type mismatch with previous external decl of 
`const char* const holiday_strings[3]'
  mc_enum_test_aux.cpp:42: error: previous external decl of `const char* const 
holiday_strings[2]'
  mc_enum_test_aux.hpp:34: error: declaration of `const char* const 
holiday_strings[3]'
  mc_enum_test_aux.cpp:42: error: conflicts with previous declaration `const 
char* const holiday_strings[2]'
  mc_enum_test_aux.hpp:36: error: could not convert template argument 
`holiday_strings' to `const char* const (&)[3]'
which is difficult to misunderstand, and como now says:
  "\lmi/src/lmi/mc_enum_test_aux.hpp", line 34: error #147: declaration is
          incompatible with "const char *const holiday_strings[2]" (declared
          at line 42 of "\lmi/src/lmi/mc_enum_test_aux.cpp")
  extern char const*const holiday_strings[3];
                          ^

> The other reason is that my patch allowed for mc_enum_type_info
> specializations not based on mc_enum_type_info_impl (for further
> refactoring to improve locality of enums metadata in the sources).

You had alluded to further refactoring opportunities, and I thought I
had divined your intent--see the patch below [0], which improves the
locality of metadata, and also abolishes the "include this file at the
end of that other file" idiom that just feels wrong, and wasn't validly
used in my first attempt, as you pointed out here:
  http://lists.nongnu.org/archive/html/lmi/2010-02/msg00004.html

Is this what you had in mind? I want to make changes like that (in
other files, too), but first I'd like to know whether you have other
ideas that may be better. But I won't make any such changes right now
because your "mc_enum<rounding_style>" patch should come first.

---------

[0] "the patch below"

Index: mc_enum_test.cpp
===================================================================
--- mc_enum_test.cpp    (revision 4777)
+++ mc_enum_test.cpp    (working copy)
@@ -27,7 +27,6 @@
 #endif // __BORLANDC__

 #include "mc_enum.hpp"
-#include "mc_enum.tpp"
 #include "mc_enum_test_aux.hpp"

 #include "test_tools.hpp"
@@ -35,20 +34,9 @@
 #include <sstream>
 #include <stdexcept>

-// Ni'ihau is deliberately (mis)spelled with an underbar instead of an
-// apostrophe, in order to test provide_for_backward_compatibility().
+// Enumerative types 'e_holiday' and 'e_island' are explicitly
+// instantiated in a different translation unit.

-enum enum_island {i_Easter = 37, i_Pago_Pago = -17, i_Ni_ihau = 13};
-extern enum_island const island_enums[] = {i_Easter, i_Pago_Pago, i_Ni_ihau};
-extern char const*const island_strings[] = {"Easter", "Pago Pago", "Ni_ihau"};
-template<> struct mc_enum_key<enum_island>
-  :public mc_enum_data<enum_island, 3, island_enums, island_strings> {};
-template class mc_enum<enum_island>;
-typedef mc_enum<enum_island> e_island;
-
-// Enumerative type 'e_holiday' is explicitly instantiated in a
-// different translation unit.
-
 struct mc_enum_test
 {
     static void test();
@@ -196,8 +184,8 @@
     ss >> holiday5;
     BOOST_TEST_EQUAL(Pentecost, holiday5);

-    // Test an enum class defined in this translation unit that has a
-    // std::string name that matches one in a different class.
+    // Test an enumerative class that has a std::string name that
+    // matches one in a different enumerative class.
     e_island island0;
     BOOST_TEST_EQUAL("Easter", island0);
     BOOST_TEST_EQUAL(i_Easter, island0);
Index: mc_enum_test_aux.cpp
===================================================================
--- mc_enum_test_aux.cpp        (revision 4780)
+++ mc_enum_test_aux.cpp        (working copy)
@@ -26,27 +26,26 @@
 #   pragma hdrstop
 #endif // __BORLANDC__

-#include "mc_enum.hpp"
 #include "mc_enum.tpp"
-#include "mc_enum_test_aux_enums.hpp" // Plain enums.
+#include "mc_enum_test_aux.hpp"

-// Normally, one would prefer to instantiate all mc_enum templates
-// in a single file. Here, however, the point is to instantiate one
-// such template in a different translation unit than the unit-test
-// driver, in order to prove that explicit instantiation works.
-
-extern enum_holiday const holiday_enums[] =
-    {h_Theophany
-    ,h_Easter
-    ,h_Pentecost
-    };
-extern char const*const holiday_strings[] =
-    {"Theophany"
-    ,"Easter"
-    ,"Pentecost"
-    };
+extern enum_holiday const holiday_enums[] = {h_Theophany, h_Easter, 
h_Pentecost};
+extern char const*const holiday_strings[] = {"Theophany", "Easter", 
"Pentecost"};
+template<> struct mc_enum_key<enum_holiday>
+  :public mc_enum_data<enum_holiday, 3, holiday_enums, holiday_strings> {};
 template class mc_enum<enum_holiday>;

+// Ni'ihau is deliberately (mis)spelled with an underbar instead of an
+// apostrophe, in order to test provide_for_backward_compatibility().
+
+extern enum_island const  island_enums[] = {i_Easter, i_Pago_Pago, i_Ni_ihau};
+extern char const*const island_strings[] = {"Easter", "Pago Pago", "Ni_ihau"};
+template<> struct mc_enum_key<enum_island>
+  :public mc_enum_data<enum_island, 3, island_enums, island_strings> {};
+template class mc_enum<enum_island>;
+
+// *** This complication is no longer necessary:
+//
 // Explicit instantiation of class mc_enum above does not require a
 // definition of mc_enum_key<T>, which does not appear in the class
 // definition. However, because mc_enum_key<T> is used in the bodies
@@ -58,5 +57,3 @@
 // time: this is the motivation for keeping class template mc_enum
 // and its metadata physically separate.

-#include "mc_enum_test_aux.hpp"
-
Index: mc_enum_test_aux.hpp
===================================================================
--- mc_enum_test_aux.hpp        (revision 4777)
+++ mc_enum_test_aux.hpp        (working copy)
@@ -27,14 +27,10 @@
 #include "config.hpp"

 #include "mc_enum_fwd.hpp"
-#include "mc_enum_metadata.hpp"
 #include "mc_enum_test_aux_enums.hpp"

-extern enum_holiday const holiday_enums[3];
-extern char const*const holiday_strings[3];
-template<> struct mc_enum_key<enum_holiday>
-  :public mc_enum_data<enum_holiday, 3, holiday_enums, holiday_strings> {};
 typedef mc_enum<enum_holiday> e_holiday;
+typedef mc_enum<enum_island> e_island;

 #endif // mc_enum_test_aux_hpp

Index: mc_enum_test_aux_enums.hpp
===================================================================
--- mc_enum_test_aux_enums.hpp  (revision 4777)
+++ mc_enum_test_aux_enums.hpp  (working copy)
@@ -31,6 +31,11 @@
     ,h_Easter    = 20040411
     ,h_Pentecost = 20040530
     };
+enum enum_island
+    {i_Easter    =  37
+    ,i_Pago_Pago = -17
+    ,i_Ni_ihau   =  13
+    };

 #endif // mc_enum_test_aux_enums_hpp






reply via email to

[Prev in Thread] Current Thread [Next in Thread]