C++ Range - for_each4:invoke

本文详细分析了C++中的invoke函数,包括operator ()、CPP_ret、meta::invoke、enable_if_t及其在for_each中的应用。CPP_ret模拟了概念,只有在特定条件下才返回指定类型。meta::invoke用于元编程中调用函数。同时介绍了enable_if_t的用法,它将enable标志放在了类型定义之后。最后,文章讨论了coerce的作用以及invoke在不同情况下的调用方式。
摘要由CSDN通过智能技术生成

invoke

在for_each2节中讲到for_each的调用函数invoke,在第for_each3节中,分析了一个关键宏CPP_auto_fun的实现,发现原来的代码中,Eric的例子返回值应该需要auto,给他提了patch. 这节回到invoke的分析。

operator ()

  template<class F, class T, class T1, class... Args>
  constexpr auto CPP_auto_fun(operator())(F T::*f, T1&& t1, Args&&... args)(const)
  (
      return (invoke_fn::coerce<T>(static_cast<T1&&>(t1), 0).*f)
          (static_cast<Args&&>(args)...)
  )

经过CPP_auto_fun的扩展

  template<class F, class T, class T1, class... Args>
  constexpr auto operator() (F T::*f, T1&& t1, Args&&... args) 
  		const noexcept(noexcept(decltype((invoke_fn::coerce<T>(static_cast<T1&&>(t1), 0).*f) (static_cast<Args&&>(args)...))((invoke_fn::coerce<T>(static_cast<T1&&>(t1), 0).*f) (static_cast<Args&&>(args)...))))
  		 -> decltype((invoke_fn::coerce<T>(static_cast<T1&&>(t1), 0).*f) (static_cast<Args&&>(args)...)) 
{ 
·  return ((invoke_fn::coerce<T>(static_cast<T1&&>(t1), 0).*f) (static_cast<Args&&>(args)...)); 
}

这个的关键是coerce的作用; 要分析coerce 先要分析两个宏定义:

CPP_ret

#if CPP_CXX_CONCEPTS
#define CPP_ret(...)                                                            \
    __VA_ARGS__ CPP_PP_EXPAND                                                   \
    /**/
#else
#define CPP_ret                                                                 \
    CPP_broken_friend_ret                                              
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分析蓝牙打印”05-22 20:55:15.340 3861 3861 W ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@1702c5f 05-22 20:55:15.405 3861 3861 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1005 android.content.ContextWrapper.sendBroadcast:444 com.zhiying.bluetoothmodelservice.MainActivity.sendBroadcast:643 com.zhiying.bluetoothmodelservice.MainActivity.onCreate:84 android.app.Activity.performCreate:7136 05-22 20:55:15.409 1936 5786 E ActivityManager: Sending non-protected broadcast android.newlink.exit.bluetoothSpeaker from system 3861:com.zhiying.bluetoothmodelservice/1000 pkg com.zhiying.bluetoothmodelservice 05-22 20:55:15.419 1936 5786 E ActivityManager: Sending non-protected broadcast android.newlink.exit.bluetoothSpeaker from system 3861:com.zhiying.bluetoothmodelservice/1000 pkg com.zhiying.bluetoothmodelservice 05-22 20:55:15.491 1797 1797 I MediaPlayerFactory: [getNameByPid:285] pid(3861), cmdline task_name(com.zhiying.bluetoothmodelservice). 05-22 20:55:15.561 3861 5918 W MediaPlayerNative: info/warning (710, 20) 05-22 20:55:15.562 3861 5918 W MediaPlayerNative: info/warning (710, 40) 05-22 20:55:15.610 3861 5918 W MediaPlayerNative: info/warning (710, 80) 05-22 20:55:15.628 3861 5918 W MediaPlayerNative: info/warning (710, 90) 05-22 20:55:15.628 3861 3861 I bt.sink.btconAc: true-------service-------- 05-22 20:55:15.628 3861 5918 W MediaPlayerNative: info/warning (710, 100) 05-22 20:55:15.629 3861 3861 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 com.zhiying.bluetoothmodelservice.MainActivity.setBluetoothServiceStatus:354 com.zhiying.bluetoothmodelservice.MainActivity.initData:187 com.zhiying.bluetoothmodelservice.MainActivity.onCreate:89 05-22 20:55:15.649 3861 3861 I UartUtils: setState: true 05-22 20:55:15.649 3861 3861 I HiMW_TVClient: [invoke:53] =============invoke cmd = 0xf10a=======begin============= 05-22 20:55:15.653 3861 3861 I HiMW_TVClient: [invoke:65] =============invoke cmd = 0xf10a=======end=============== 05-22 20:55:15.654 3861 3861 W AudioManager: Use of stream types is deprecated for operations other than volume control 05-22 20:55:15.654 3861 3861 W AudioManager: See the documentation of requestAudioFocus() for what to use instead with android.media.AudioAttributes to qualify your playback use case 05-22 20:55:15.655 1936 5786 I MediaFocusControl: requestAudioFocus() from uid/pid 1000/3861 clientId=android.media.AudioManager@3140a29 callingPack=com.zhiying.bluetoothmodelservice req=2 flags=0x0 sdk=29 05-22 20:55:15.658 3861 3861 D bt.sink.btconAc: onResume: 05-22 20:55:15.658 3861 3861 D bt.sink.btconAc: getBreathingScreenDatas: Could not find remote control icon properties 05-22 20:55:15.702 3861 3861 I bt.sink.btsevice: blueToothChange:关闭 05-22 20:55:15.706 3861 3861 D BluetoothAdapter: enable(): BT already enabled! 05-22 20:55:15.738 3861 3894 I ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 05-22 20:55:15.738 3861 3894 I ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retriev
05-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值