[Top][All Lists]

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

Re: [lmi] clang 10/C++20 build fixes

From: Vadim Zeitlin
Subject: Re: [lmi] clang 10/C++20 build fixes
Date: Sat, 4 Apr 2020 18:00:14 +0200

On Sat, 4 Apr 2020 15:08:53 +0000 Greg Chicares <address@hidden> wrote:

GC> On 2020-04-04 00:09, Vadim Zeitlin wrote:
GC> > On Fri, 3 Apr 2020 22:53:50 +0000 Greg Chicares <address@hidden> wrote:
GC> [...]
GC> > GC>   grep '[io]stream' rate_table.hpp
GC> > GC>       database(std::istream& index_is, std::shared_ptr<std::istream> 
GC> > GC>       void save(std::ostream& index_os, std::ostream& data_os);
GC> > GC>   inline std::ostream& operator<<(std::ostream& os, table::Number 
const& number)
GC> > GC> 
GC> > GC> AFAICT, both std::istream and std::ostream are mentioned either
GC> > GC>  - by reference, or
GC> > GC>  - in the template parameter of std::shared_ptr
GC> > GC> so I thought the ideal fix would be to add
GC> > GC>   #include <iosfwd>
GC> > GC> to the header,
GC> > 
GC> >  No, this is insufficient, std::ostream is actually used in the inline
GC> > implementation of operator<<() overload for table::Number.
GC> Oh. I rewrote it to make my first impression correct, by moving
GC> the implementation out of line. I trust clang will accept that.

 Yes, I can confirm it does, thank you.

GC> > GC> Even after pulling this PR, this command:
GC> > GC>   grep 'std::bind[12]' *.?pp
GC> > GC> finds more occurrences. Do you want to lambda-ize those, too?
GC> > 
GC> >  I see only 3 other occurrences and 2 of them are inside commented out 
GC> > in interest_rates.cpp which I did notice, but decided not to modify 
GC> > I don't think this would be especially useful (just removing the commented
GC> > out code entirely would arguably be more so), but please let me know if 
GC> > feel differently about this.
GC> I do, so I changed it...

 Thanks, now I can get past this error when compiling this test, but
unfortunately there is another one later due to not defining copy ctor
explicitly for some ublas-related type deep inside Boost headers in spite
of defining an assignment operator for it. I don't know if it's worth
making a new PR for this, but here is a patch doing the same change already
done in boost_regex.hpp in a88f40208 (Disable clang -Wdeprecated-copy
warning in regex_iterator, 2020-03-25):
---------------------------------- >8 --------------------------------------
diff --git a/expression_template_0_test.cpp b/expression_template_0_test.cpp
index 2d5c203bb..920ccffd7 100644
--- a/expression_template_0_test.cpp
+++ b/expression_template_0_test.cpp
@@ -43,7 +43,14 @@
 #include "timer.hpp"

 #if defined USE_UBLAS
+#   if defined __clang__
+#      pragma clang diagnostic push
+#      pragma clang diagnostic ignored "-Wdeprecated-copy"
+#   endif
 #   include <boost/numeric/ublas/vector.hpp>
+#   if defined __clang__
+#      pragma clang diagnostic pop
+#   endif
 #endif // defined USE_UBLAS

 #include <algorithm>
---------------------------------- >8 --------------------------------------

 With this, "make test_expression_template_0" succeeds with clang too.

GC> >  The remaining case, in expression_template_0_test.cpp, went unnoticed
GC> > because I didn't compile this test with clang, but I should indeed fix it
GC> > -- and I'll do it once I have some sleep and can be sure I don't do
GC> > anything stupid. Thanks for noticing it!
GC> ...and that, too. It's amazing how difficult it is to use this approach
GC> to write the equivalent of APL's
GC>   Mly7702ig←¯1+÷DBDiscountRate
GC> which is why, if I want to know what this code does, I read the comment:
GC>   // ET !! Mly7702ig = -1.0 + 1.0 / DBDiscountRate;
GC> and see that it's just 'A←¯1+÷B': "negative one plus reciprocal".

 I still have secret hope for rewriting lmi in Raku (née Perl 6) one day as
this is clearly what you'd like to use. Just look:

        $ rakudo
        To exit type 'exit' or '^D'
        > @nums = 1..5
        [1 2 3 4 5]
        > @result = -1 «+« 1 «/« @nums
        [0 -0.5 -0.666667 -0.75 -0.8]

Aren't hyper-operators nice? They even use weird Unicode characters too
(using "<<" instead would work too, but clearly would make them less
appealing). And, AFAIK unlike APL, it doesn't lose any precision as the
results of these operations are rational numbers:

        > @result[2].WHAT
        > (@result[2].numerator, @result[2].denominator)
        (-2 3)
        > @result[2]*3

(and not something stupid like -2.0000000001).


Attachment: pgpR_MVDChbEH.pgp
Description: PGP signature

reply via email to

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