0

I saw such codes in LLVM source codes:

template <typename PassT, typename IRUnitT, typename AnalysisManagerT,
          typename... ArgTs, size_t... Ns>
typename PassT::Result
getAnalysisResultUnpackTuple(AnalysisManagerT &AM, IRUnitT &IR,
                             std::tuple<ArgTs...> Args,
                             std::index_sequence<Ns...>) {
  (void)Args;
  return AM.template getResult<PassT>(IR, std::get<Ns>(Args)...);
}

It seems not to need to explain the context, because all of the arguments are template arguments. What confuses me is the body of this function. First, I really can't get what does the first statement do:

(void)Args;

To my knowledge, this just cast Args to void to a temporary variable. And the temporary variable will be desconstructed immediately after this statement. It seems like totally meanningless.

And the second statement confuses me about its grammer:

return AM.template getResult<PassT>(IR, std::get<Ns>(Args)...);

I really don't know what is the meaning of .template stand for. I searched .template in the search engine but get nothing. I don't know what does the .template do here. And I am wondering why don't implement it just like:

return AM.getResult<PassT>(IR, std::get<Ns>(Args)...);

What's the difference?

user207421
  • 305,947
  • 44
  • 307
  • 483
yodahaji
  • 717
  • 1
  • 5
  • 10
  • https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – Mat Mar 20 '20 at 05:21
  • The flagged duplicate answers the question in your title. I can't find a proper duplicate for your other question about the cast to `void`, but it's usually to suppress unused parameter warnings by the compiler. Doesn't seem necessary in this case though, since `Args` is used. – Miles Budnek Mar 20 '20 at 05:25
  • 1
    @MilesBudnek It is necessary because GCC will warn if the pack expansion is empty and doesn't use `Args` in an instantiation: https://godbolt.org/z/bpzXYi – walnut Mar 20 '20 at 05:30
  • @walnut Huh, I didn't even realize a 0-length tuple was legal. TIL. – Miles Budnek Mar 20 '20 at 05:32

0 Answers0