Skip to content

Explanation about decltype used in typechecker_spec.lua #88

Answered by edubart
stefanos82 asked this question in Q&A
Discussion options

You must be logged in to vote

The decltype in Nelua is a generic that returns the type of an identifier or expression.

Does this mean y's decltype behavior is like C++14's decltype(auto) in this case?

Not exactly, Nelua's decltype is similar to C++'s decltype because you can use both to get a type from an identifier or expression, but decltype(auto) in C++ is used only to automatic detect the type for function returns while in Nelua the same is done just with auto or leaving the function returns without type notations.

Here is a small example of decltype usage:

local function bounded_increment(x: auto): auto
  local y: decltype(x) = x + 1
  if y <= x then -- value wrapped around due to integer overflow
    y = x
  end

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stefanos82
Comment options

Answer selected by edubart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants