Question: I have an endpoint that requests the current logged in user.

`GET /user/current`
[source](https://stackoverflow.com/questions/36520372/designing-uri-for-current-logged-in-user-in-rest-applications)

If a user is found, the server sends `200 OK` and the user object.

But what if no one is logged in? Should the server send back `200 Ok` with an empty object?

This [post](https://stackoverflow.com/questions/11746894/what-is-the-proper-rest-response-code-for-a-valid-request-but-an-empty-data) asked a similar question:

> 
> For example you run a GET request for users/9 but there is no user with id #9. Which is the best response code?
> 
> 
> 

The top answer was `404 Not Found`. But this doesn't seem correct to me for a current user request with no logged in user. In this case the answer was found- the answer is that no user is logged in.

Answer: 
You are overcomplicating things. `std::string_view` can be constructed by `const char*`:

```
constexpr bool ContainsAsterisk(std::string_view view) {
    // constexpr bool b = view.find('*') != view.npos; // ERROR
    return view.find('*') != view.npos;
}

int main() {
  constexpr bool b = ContainsAsterisk("123123*"); // OK
}

```

> 
> Why am I getting the error?
> 
> 
> 

According to [cppreference](https://en.cppreference.com/w/cpp/language/constexpr), a function can be constexpr if:

> 
> there exists at least one set of argument values such that an
> invocation of the function could be an evaluated subexpression of a
> core constant expression [...]
> 
> 
> 

This means that it's not necessary for a `constexpr` function to always return a `constexpr` value, neither is it expected to always receive a `constexpr` argument. It only makes sure that for some specific set of arguments (a `constexpr const char*` in thie case), it will give a `constexpr` return value.

Therefore, a definition that assumes the argument is always `constexpr` (see ERROR line above) is invalid.
You already have answers on how else to do this so I wont add anything more to that but this answer will address

> 
> I don't understand how the variable is being read outside it's lifetime, it's a literal (isn't it?) that I thought would be available at compile time.
> 
> 
> 

Yes, a string literal is a compile time constant. The issue here is that a function parameter is not a compile time constant, even if it is initialized from one. To see why that is, lets start with the function

```
template <auto var>
auto foo()
{
    if constexpr (var == 1)
        return 1;
    else
        return 1.0;
}

```

This function template will have two different return types, but only one of them will ever be used in a specialization so you still follow the rule of one return type per function. Now if we allowed constexpr function parameters like

```
auto foo(constexpr int var)
{
    if constexpr (var == 1)
        return 1;
    else
        return 1.0;
}

```

This function will either return a `int` or a `double`, but you can't have one function that has different return types.