简体   繁体   中英

Strange C++ syntax in vulkan-hpp

I have been having a look into the vulkan-hpp source code to try to understand how to manage StructureChain s. I've found this odd looking syntax (line marked with comment) related with the usage of template keyword as a member type. Moreover, its followed by a function call with no ; preceding.

  template<typename X, typename Y, typename ...Z, typename Dispatch>
  VULKAN_HPP_INLINE StructureChain<X, Y, Z...> PhysicalDevice::getFormatProperties2( VULKAN_HPP_NAMESPACE::Format format, Dispatch const &d ) const VULKAN_HPP_NOEXCEPT
  {
    StructureChain<X, Y, Z...> structureChain;
    VULKAN_HPP_NAMESPACE::FormatProperties2& formatProperties = structureChain.template get<VULKAN_HPP_NAMESPACE::FormatProperties2>(); //This line
    d.vkGetPhysicalDeviceFormatProperties2( m_physicalDevice, static_cast<VkFormat>( format ), reinterpret_cast<VkFormatProperties2*>( &formatProperties ) );
    return structureChain;
  }

Can anyone help me to figure out the meaning of this line?

This template keyword is used to disambiguate the following expression as a template instantiation.

structureChain type depends on template parameters, so the compiler cannot know how to interpret the following get<VULKAN_HPP_NAMESPACE::FormatProperties2 expression, which may be an instantiation of a get template, or comparison expression. The template keyword indicates that get is a template, and the following is a template instantiation. In the absence of this keyword the compiler would assume get is not a template, so the following must be a comparison expression.

See here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM