lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 6921ed7 3/6: Belay array decay


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 6921ed7 3/6: Belay array decay
Date: Sat, 28 Jan 2017 04:52:22 +0000 (UTC)

branch: master
commit 6921ed7cb6488d88ede3563e81753eccea429c7d
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Belay array decay
    
    This change sacrifices some clarity due to the typedef (which prevents
    lines from wrapping) for the sake of maintainability (recent changes
    demonstrate the dangers of 'char const* const* p = nullptr').
    
    Function check() is no shorter, because the default for argument 'c'
    is still "special" (but constructed of Fe rather than Pu). Of course,
    'c' could be defaulted to a vector of length 'n' if 'n' were made a
    non-type template parameter, but that would not be simpler.
    
    There is no need to change 'd' from array to vector: its cardinality
    'n' must be passed to check() anyway for use as an InputSequence ctor
    argument; and it is never defaulted, so there is no reason to default
    it to nullptr.
---
 input_seq_test.cpp |   26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/input_seq_test.cpp b/input_seq_test.cpp
index fe36faf..2a8258d 100644
--- a/input_seq_test.cpp
+++ b/input_seq_test.cpp
@@ -36,7 +36,7 @@ void check
     ,std::string const&              e
     ,char const*                     x = ""
     ,std::vector<std::string> const& k = std::vector<std::string>()
-    ,char const* const*              c = nullptr
+    ,std::vector<std::string> const& c = std::vector<std::string>()
     ,std::string const&              w = std::string()
     )
 {
@@ -56,9 +56,9 @@ void check
 
     std::vector<std::string> const& s(seq.linear_keyword_representation());
     std::vector<std::string> const t =
-        (nullptr == c)
+        ( std::vector<std::string>() == c)
         ? std::vector<std::string>(n)
-        : std::vector<std::string>(c, c + n)
+        : c
         ;
     bool const bs = s == t;
     if(!bs)
@@ -90,6 +90,8 @@ void check
 
 int test_main(int, char*[])
 {
+    using strvec = std::vector<std::string>;
+
     // Arguments to check():
     //   expected results
     //     c: keywords
@@ -299,20 +301,20 @@ int test_main(int, char*[])
     // Test (enumerative) extra keywords.
     {
     int const n = 9;
-    char const* c[n] = {"a", "a", "ccc", "ccc", "b", "b", "b", "b", "b"};
-    double const d[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+    strvec const c      {"a", "a", "ccc", "ccc", "b", "b", "b", "b", "b"};
+    double const d[n] = { 0 ,  0 ,   0  ,   0  ,  0 ,  0 ,  0 ,  0 ,  0 };
     std::string const e("a[0, 2); ccc [2, 4);b[4, 6);");
-    std::vector<std::string> const k{"not_used", "a", "b", "c", "cc", "ccc"};
+    strvec const k{"not_used", "a", "b", "c", "cc", "ccc"};
     check(__FILE__, __LINE__, d, n, e, "", k, c);
     }
 
     // Test numbers mixed with (enumerative) extra keywords.
     {
     int const n = 9;
-    char const* c[n] = {"", "", "keyword_00", "keyword_00", "", "", "", "", 
""};
-    double const d[n] = {1, 1, 0, 0, 5, 5, 7, 7, 7};
+    strvec const c     {"", "", "keyword_00", "keyword_00", "", "", "", "", 
""};
+    double const d[n] ={ 1,  1,       0     ,       0     ,  5,  5,  7,  7,  
7};
     std::string const e("1 [0, 2); keyword_00 [2, 4); 5 [4, 6); 7");
-    std::vector<std::string> const k{"keyword_00"};
+    strvec const k{"keyword_00"};
     check(__FILE__, __LINE__, d, n, e, "", k, c);
     }
 
@@ -320,10 +322,10 @@ int test_main(int, char*[])
     // a default keyword.
     {
     int const n = 10;
-    char const* c[n] =  {"b", "b", "x", "a", "x", "x", "a", "x", "x", "x"};
-    double const d[n] = {  0,   0,   0,   0,   5,   5,   0,   7,   7,   7};
+    strvec const c      {"b", "b", "x", "a", "x", "x", "a", "x", "x", "x"};
+    double const d[n] = { 0 ,  0 ,  0 ,  0 ,  5 ,  5 ,  0 ,  7 ,  7 ,  7 };
     std::string const e("b [0, 2); a [3, 4); 5 [4, 6); a; 7");
-    std::vector<std::string> const k{"a", "b", "x"};
+    strvec const k{"a", "b", "x"};
     std::string w("x");
     check(__FILE__, __LINE__, d, n, e, "", k, c, w);
     }



reply via email to

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