mardi 27 février 2018

Calling processing constexpr at runtime. C++

Please see the code below:

#include <iostream>

constexpr int f(int a, int b)
{
    return a<b? a : throw std::out_of_range("out of range");    
}

int main() 
{
    try
    {
        int n = 0;
        f(5, n);
    }
    catch(const std::exception& ex)
    {
        std::cout<<"Exception caught"<<std::endl;
        std::cout<<ex.what()<<std::endl;
    }
}

I know that constexprt functions are processed at compile time. So how it came that I can pass a "runtime" local varialbe to it and use it in try-catch block again in runtime? Maybe I am missing smth regargind constexprt functions?

Aucun commentaire:

Enregistrer un commentaire