首页 > 其他分享 >template - function parameter - type

template - function parameter - type

时间:2023-06-19 10:12:36浏览次数:44  
标签:function std type same static template include parameter

#include <iostream>
#include <thread>
#include <array>
#include <functional>

template <auto func, std::size_t I>
struct param_type;

template <typename Ret, typename... Args, Ret (*func)(Args...), std::size_t I>
struct param_type<func, I>
{
    using type = std::tuple_element_t<I, std::tuple<Args...>>;
};

template <typename Ret, typename... Args, Ret (*func)(Args..., ...), std::size_t I>
struct param_type<func, I>
{
    using type = std::tuple_element_t<I, std::tuple<Args...>>;
};


void foo(std::string const&, int, char&) {
    //...
}

static_assert(std::is_same_v<const std::string&, param_type<&foo, 0>::type>);
static_assert(std::is_same_v<int, param_type<&foo, 1>::type>);
static_assert(std::is_same_v<char&, param_type<&foo, 2>::type>);

https://stackoverflow.com/questions/70612294/getting-parameter-type-of-function-with-templates

标签:function,std,type,same,static,template,include,parameter
From: https://www.cnblogs.com/Searchor/p/17490406.html

相关文章

  • CF455E. Function
    感觉不难啊,为什么是*2900捏。发现这个玩意的本质是最初在r,每次不动或向左移动一步,进行l次操作,求每次停留的格子权值之和的最小值。显然我们只会停留在至多一个格子上,假设停留在\(i\),那么权值之和就是\(\left(l-r+i\right)a_i+\sum\limits_{j=i+1}^ra_j\),且\(i\in[r-l+1,r......
  • 用 Typescript 搭建 Nodejs Server
    Typescript是微软开发的自由和开源的变成语言,是Javascript的超集,它可以编译成Javascript。Typescript支持Javascript的语法,同时它又包含了类型定义、接口、枚举、泛型等很多后端语言的特点,能在编译时支持类型检查,因此可以很好的提升代码质量。本文将演示如何使用Typescipt......
  • 执行存储过程报错:User does not have access to metadata required to determine stor
    在执行存储过程中,报错详细信息如下:java.sql.SQLException:Userdoesnothaveaccesstometadatarequiredtodeterminestoredprocedureparametertypes.Ifrightscannotbegranted,configureconnectionwith"noAccessToProcedureBodies=true"tohavedrivergener......
  • [ts]typescript高阶之typeof使用
    LcukyCola前端工具官网:https://luckycola.com.cn/public/dist/#/前言学习目标1、typeof与对象结合使用2、typeof与枚举结合使用3、typeof与class类结合使用4、const断言的使用一、typeof与对象结合使用代码如下(示例):letlolo={name:'zhanhsan',age:18,ch......
  • 懒加载与急加载FetchType.LAZY&FetchType.EAGER的区别和使用?
    1、FetchType.LAZY:懒加载,加载一个实体时,定义懒加载的属性不会马上从数据库中加载。2、FetchType.EAGER:急加载,加载一个实体时,定义急加载的属性会立即从数据库中加载。3、比方User类有两个属性,name跟address,登录后用户名是需要显示出来的,此属性用到的几率极大,要马上到数据库查,用......
  • [Go] 理解 Go 的 unintptr、unsafe.Pointer、*type
    理解Go的unintptr、unsafe.Pointer、*type概念*type:用于传递对象地址,无法进行指针运算unsafe.Pointer:通用指针,用于表示任意类型的指针,无法进行指针运算,无法读取存储的值,可作为对象引用任意类型的指针可以转换为unsafe.Pointerunsafe.Pointer可以转换为任......
  • 【Azure 应用服务】Azure Data Factory中调用Function App遇见403 - Forbidden
    问题描述在AzureDataFactory(数据工厂)中,调用同在Azure中的FunctionApp函数,却出现403-Forbidden错误。截图如下:  问题解答访问AzureFunctionApp遇见403-Forbidden错误,这是因为FunctionApp启用了限制访问功能,在其中配置了允许访问的IP地址列表,而从ADF中发出的请求使用的I......
  • 【Azure 应用服务】Azure Function App在部署时候遇见 503 ServiceUnavailable
    问题描述在VSCode中编写好AzureFunctionApp代码后,通过 funcazurefunctionapppublish部署失败,抛出503ServiceUnavailable错误。Gettingsitepublishinginfo...Creatingarchiveforcurrentdirectory...Performingremotebuildforfunctionsproject.Deleting......
  • Cannot Reference “XxxClass.xxxmember” Before Supertype Constructor Has Been Ca
    在调用超类型构造函数之前无法引用“XxxClass.xxx”-----在一个类的构造器方法还未执行的时候,我们无法使用这个类的成员属性或成员方法。百度翻译:在调用超类型构造函数之前无法引用“XxxClass.xxx”-----我的理解:在一个类的构造器方法还未执行的时候,我们......
  • JavaScript & TypeScript 学习总结
    @目录JavaScriptJavaScriptBOM对象JavaScriptDocument对象JavaScript事件处理JavaScript变量JavaScript函数基础JavaScript流程控制JavaScript数据类型JavaScript数组JavaScript运算符JavaScript正则表达式JavaScript字符串函数TypeScript简单示例JavaScriptJavaScriptBOM对......