Results 1 to 2 of 2

Thread: C++ constexpr experiments

  1. #1
    Administrator Shelwien's Avatar
    Join Date
    May 2008
    Location
    Kharkov, Ukraine
    Posts
    3,134
    Thanks
    179
    Thanked 921 Times in 469 Posts

    C++ constexpr experiments

    test-crc.cpp: compile-time crc32 calculation
    https://godbolt.org/z/vCT5tA


    test-format-str.cpp: compile-time printf format string generation based on arg types
    https://godbolt.org/z/cCmYTi


    test-concat.cpp: compile-time string concatenation
    https://godbolt.org/z/gF5_y7
    Attached Files Attached Files

  2. The Following User Says Thank You to Shelwien For This Useful Post:

    encode (23rd February 2019)

  3. #2
    Administrator Shelwien's Avatar
    Join Date
    May 2008
    Location
    Kharkov, Ukraine
    Posts
    3,134
    Thanks
    179
    Thanked 921 Times in 469 Posts
    test-concat2.cpp: compile-time string concatenation attempt #2
    https://godbolt.org/z/IszYEH

    Previous attempt actually created _an initializer_ for a string.
    Sure, gcc optimizes it to copying of an actual static string...
    but IntelC doesn't - it generates a sequence of byte writes which construct the string in runtime.

    Well, now there's an actual static string which isn't copied anywhere.

    The main problem: its apparently prohibited to use constexpr on function arguments,
    so any constexpr var passed to a function turns into not-constexpr.
    Ok, but its possible to create a local class with constexpr methods
    which return these arguments, and pass its instance to a function.

    Problem #2: to let function call still look normal, we can make a macro wrapper
    which would automatically convert arguments into return values of constexpr methods.
    Gcc has a problem with creating an anonymous instance of anonymous struct inplace,
    like func( struct{}() ), but somehow its not a problem if its an inplace lambda returning that struct.

    Problem #3: this specific source works in gcc,intelC,clang, but not in VS -
    looks like VS can't access symbols of a constexpr string as constexpr.
    Well, its not like anybody uses it... :)
    Attached Files Attached Files

  4. The Following User Says Thank You to Shelwien For This Useful Post:

    joerg (26th February 2019)

Similar Threads

  1. Experiments with orderN-CM
    By Sebastian in forum Data Compression
    Replies: 91
    Last Post: 11th January 2012, 01:09
  2. Experiments with small dictionary coding
    By Matt Mahoney in forum Data Compression
    Replies: 13
    Last Post: 28th June 2010, 16:34
  3. Ordered bitcodes experiments
    By Shelwien in forum Data Compression
    Replies: 19
    Last Post: 30th May 2009, 03:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •