Convert code to constexpr

What are the general tips for converting code to constexpr? Let's say there is an algorithm for some geometrical transmorcation (input) of a geometric figure. Entrance and exit differ in nature and size and depend on each other non-trivially. Currently, it is implemented as a class in which it is currently used std::mapand std::vector(without loss of generality).

What is a refactoring method that uses dynamic memory to get code that meets the requirements for constant expressions?

I can imagine some combination of constexprcontainer packages and a constexprcompatible stack distributor implementation (for large enough storage) for each container used value_type. But there is a problem: I have never met such containers. But maybe there are other ways?

+4
source share
1 answer

(std::bitset, std::array ..) constexpr constexpr. , . . Q & A.

, , , ( 5.20 [expr.const] )

  • ( std::inplace_merge .)
  • ( <iostream>)
  • - ( N4487)
  • reinterpret_cast
  • goto (, N4472)

  • , new/delete constexpr.
  • ( constexpr) a switch.
  • lambdas a constexpr operator().
  • reinterpret_cast constexpr ( union ).
  • goto , .

new/delete . / .

, constexpr ++ 14/17, . , constexpr ( , noexcept).

++, , constexpr ( , ).

+5

Source: https://habr.com/ru/post/1625339/


All Articles