C++Guns – RoboBlog blogging the bot

24.08.2020

C++ Guns: C++20 und UTF8 Unicode

Filed under: Allgemein — Tags: — Thomas @ 11:08

In C++20 ändert sich der Typ von u8 string literals von char nach char8_t. Damit compiliert älterer Code nicht mehr

GCC10 Error so far:

error: use of deleted function 'std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char8_t*) [with _Traits = std::char_traits<char>]'

Ich sag es mal positiv: ein weitere Schritt ist gemacht. Und bis dahin behelfen wir uns mit dreckigen casts:

auto func(std::ostream& ss) {
    ss << reinterpret_cast<const char*>(u8"\u00e4 \u00f6 \u00fc \u2581") << "\n";
}

Ausgabe:

ä ö ü ▁

Die Verwendung von char8_t u8string und u8stringliterals ist gefühlt noch nicht ausgereift :/

19.08.2020

Fortran assert

Filed under: Allgemein — Tags: — Thomas @ 07:08

assert.h

#ifdef NDEBUG
#define assert(expr)
#else
#define assert(expr)    call assertion(expr)
#endif

assertion.F90

module assert_m
  contains
  
  subroutine assertion(cond)
    implicit none
    logical, intent(in) :: cond
    real, volatile :: r
    r = 1.0
    if (.not. cond) r = r / 0.0
  end subroutine assertion

end module

Beispiel:

#include "assert.h"

    use assert_m


    subroutine VBEST(H, RH, KZ, DFM, Q, V0, V)
      implicit none
      real, intent(in) :: H
      real, intent(in) :: RH
      integer, intent(in) :: KZ
      real, intent(in) :: DFM
      real, intent(in) :: Q

      assert(Q == Q)
      assert(H >= 0)
      assert(RH >= 0)
      assert(KZ >= 1)
      assert(DFM > 0)

Powered by WordPress