返回類型后置,一個用途是為了邏輯上的體現?

?大家一般都是先關心參數,然后最后再看返回的是什么類型。

在這里把返回類型后置,可能就是一種邏輯上的體現吧

fmt的一個函數。

\fmt\core.h

這個函數的意義,應該就是用變長參數初始化成一個format_arg_store類型的變量,并返回。

\fmt\bundled\core.h

/**\rstConstructs a `~fmt::format_arg_store` object that contains references toarguments and can be implicitly converted to `~fmt::format_args`. `Context`can be omitted in which case it defaults to `~fmt::context`.See `~fmt::arg` for lifetime considerations.\endrst*/
template <typename Context = format_context, typename... Args>
constexpr auto make_format_args(const Args&... args)-> format_arg_store<Context, Args...> {return {args...};
}

但這個怎么回事,傳進double,返回的還是double:

  FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double { return val; }

可能是因為重載其他map模板函數,比如:

 template <typename T, FMT_ENABLE_IF(is_char<T>::value)>FMT_CONSTEXPR FMT_INLINE auto map(T val) -> char_type {static_assert(std::is_same<T, char>::value || std::is_same<T, char_type>::value,"mixing character types is disallowed");return val;}注意,這個char_type是通過模板參數而來的:
using char_type = typename Context::char_type;

\fmt\bundled\core.h

// Maps formatting arguments to core types.
template <typename Context> struct arg_mapper 
{using char_type = typename Context::char_type;FMT_CONSTEXPR FMT_INLINE auto map(signed char val) -> int { return val; }FMT_CONSTEXPR FMT_INLINE auto map(unsigned char val) -> unsigned {return val;}FMT_CONSTEXPR FMT_INLINE auto map(short val) -> int { return val; }FMT_CONSTEXPR FMT_INLINE auto map(unsigned short val) -> unsigned {return val;}FMT_CONSTEXPR FMT_INLINE auto map(int val) -> int { return val; }FMT_CONSTEXPR FMT_INLINE auto map(unsigned val) -> unsigned { return val; }FMT_CONSTEXPR FMT_INLINE auto map(long val) -> long_type { return val; }FMT_CONSTEXPR FMT_INLINE auto map(unsigned long val) -> ulong_type {return val;}FMT_CONSTEXPR FMT_INLINE auto map(long long val) -> long long { return val; }FMT_CONSTEXPR FMT_INLINE auto map(unsigned long long val)-> unsigned long long {return val;}FMT_CONSTEXPR FMT_INLINE auto map(int128_t val) -> int128_t { return val; }FMT_CONSTEXPR FMT_INLINE auto map(uint128_t val) -> uint128_t { return val; }FMT_CONSTEXPR FMT_INLINE auto map(bool val) -> bool { return val; }template <typename T, FMT_ENABLE_IF(is_char<T>::value)>FMT_CONSTEXPR FMT_INLINE auto map(T val) -> char_type {static_assert(std::is_same<T, char>::value || std::is_same<T, char_type>::value,"mixing character types is disallowed");return val;}FMT_CONSTEXPR FMT_INLINE auto map(float val) -> float { return val; }FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double { return val; }FMT_CONSTEXPR FMT_INLINE auto map(long double val) -> long double {return val;}FMT_CONSTEXPR FMT_INLINE auto map(char_type* val) -> const char_type* {return val;}FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* {return val;}template <typename T, FMT_ENABLE_IF(is_string<T>::value)>FMT_CONSTEXPR FMT_INLINE auto map(const T& val)-> basic_string_view<char_type> {static_assert(std::is_same<char_type, char_t<T>>::value,"mixing character types is disallowed");return to_string_view(val);}template <typename T,FMT_ENABLE_IF(std::is_constructible<basic_string_view<char_type>, T>::value &&!is_string<T>::value && !has_formatter<T, Context>::value &&!has_fallback_formatter<T, char_type>::value)>FMT_CONSTEXPR FMT_INLINE auto map(const T& val)-> basic_string_view<char_type> {return basic_string_view<char_type>(val);}template <typename T,FMT_ENABLE_IF(std::is_constructible<std_string_view<char_type>, T>::value &&!std::is_constructible<basic_string_view<char_type>, T>::value &&!is_string<T>::value && !has_formatter<T, Context>::value &&!has_fallback_formatter<T, char_type>::value)>FMT_CONSTEXPR FMT_INLINE auto map(const T& val)-> basic_string_view<char_type> {return std_string_view<char_type>(val);}FMT_CONSTEXPR FMT_INLINE auto map(const signed char* val) -> const char* {static_assert(std::is_same<char_type, char>::value, "invalid string type");return reinterpret_cast<const char*>(val);}FMT_CONSTEXPR FMT_INLINE auto map(const unsigned char* val) -> const char* {static_assert(std::is_same<char_type, char>::value, "invalid string type");return reinterpret_cast<const char*>(val);}FMT_CONSTEXPR FMT_INLINE auto map(signed char* val) -> const char* {const auto* const_val = val;return map(const_val);}FMT_CONSTEXPR FMT_INLINE auto map(unsigned char* val) -> const char* {const auto* const_val = val;return map(const_val);}FMT_CONSTEXPR FMT_INLINE auto map(void* val) -> const void* { return val; }FMT_CONSTEXPR FMT_INLINE auto map(const void* val) -> const void* {return val;}FMT_CONSTEXPR FMT_INLINE auto map(std::nullptr_t val) -> const void* {return val;}// We use SFINAE instead of a const T* parameter to avoid conflicting with// the C array overload.template <typename T>FMT_CONSTEXPR auto map(T) -> enable_if_t<std::is_pointer<T>::value, int> {// Formatting of arbitrary pointers is disallowed. If you want to output// a pointer cast it to "void *" or "const void *". In particular, this// forbids formatting of "[const] volatile char *" which is printed as bool// by iostreams.static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");return 0;}template <typename T, std::size_t N>FMT_CONSTEXPR FMT_INLINE auto map(const T (&values)[N]) -> const T (&)[N] {return values;}template <typename T,FMT_ENABLE_IF(std::is_enum<T>::value &&!has_formatter<T, Context>::value &&!has_fallback_formatter<T, char_type>::value)>FMT_CONSTEXPR FMT_INLINE auto map(const T& val)-> decltype(std::declval<arg_mapper>().map(static_cast<typename std::underlying_type<T>::type>(val))) {return map(static_cast<typename std::underlying_type<T>::type>(val));}template <typename T,FMT_ENABLE_IF(!is_string<T>::value && !is_char<T>::value &&(has_formatter<T, Context>::value ||has_fallback_formatter<T, char_type>::value))>FMT_CONSTEXPR FMT_INLINE auto map(const T& val) -> const T& {return val;}template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>FMT_CONSTEXPR FMT_INLINE auto map(const T& named_arg)-> decltype(std::declval<arg_mapper>().map(named_arg.value)) {return map(named_arg.value);}auto map(...) -> unformattable { return {}; }
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/10726.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/10726.shtml
英文地址,請注明出處:http://en.pswp.cn/web/10726.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Rust學習筆記(上)

前言 筆記的內容主要參考與《Rust 程序設計語言》&#xff0c;一些也參考了《通過例子學 Rust》和《Rust語言圣經》。 Rust學習筆記分為上中下&#xff0c;其它兩個地址在Rust學習筆記&#xff08;中&#xff09;和Rust學習筆記&#xff08;下&#xff09;。 編譯與運行 Ru…

成功解決No module named ‘huggingface_hub.inference._text_generation‘

成功解決No module named huggingface_hub.inference._text_generation 目錄 解決問題 解決思路 解決方法 解決問題 No module named huggingface_hub.inferen

python使用yaml文件以及元組樣式字符串使用eval的類型轉換

編程中&#xff0c;對于可變內容&#xff0c;最好是將其放入配置文件中&#xff0c;經過這段時間的學習&#xff0c;感覺使用yaml文件很方便。我的環境&#xff1a;win10&#xff0c;python3.8.10。 python使用yaml文件&#xff0c;首先要安裝庫。 pip38 install pyyaml 安裝…

AWTK 開源串口屏開發(18) - 用 C 語言自定義命令

AWTK-HMI 內置了不少模型&#xff0c;利用這些模型開發應用程序&#xff0c;不需要編寫代碼即可實現常見的應用。但是&#xff0c;有時候我們需要自定義一些命令&#xff0c;以實現一些特殊的功能。 本文檔介紹如何使用 C 語言自定義命令。 1. 實現 hmi_model_cmd_t 接口 1.1…

實現二叉樹的基本操作

博主主頁: 碼農派大星. 關注博主帶你了解更多數據結構知識 1我們先來模擬創建一個二叉樹 public class TestBinaryTreee {static class TreeNode{public char val;public TreeNode left;public TreeNode right;public TreeNode(char val) {this.val val;}}public TreeNode …

交叉編譯u-boot,qemu啟動測試

交叉編譯u-boot 1 配置交叉編譯工具鏈&#xff1a; 下載地址 https://releases.linaro.org/components/toolchain/binaries/ ### CROSS-COMPILE export AARCH64_LINUX_GNU_TOOLS/media/wmx/cross_compile_tools/aarch64-linux-gun/gcc-x86_64_aarch64-linux-gnu/bin export …

linux 安裝 mangodb 并設置服務開機自啟

1、下載 wget http://mosquitto.org/files/source/mosquitto-1.6.8.tar.gz 2、解壓 tar -zxvf mosquitto-1.6.8.tar.gz 3、編譯安裝cd mosquitto-1.6.8 make sudo make install4、在當前目錄。進入mosquitto服務文件存放的文件夾 cd service/systemd可以看到3個文件 點擊read…

【C/C++】設計模式——工廠模式:簡單工廠、工廠方法、抽象工廠

創作不易&#xff0c;本篇文章如果幫助到了你&#xff0c;還請點贊 關注支持一下?>&#x16966;<)!! 主頁專欄有更多知識&#xff0c;如有疑問歡迎大家指正討論&#xff0c;共同進步&#xff01; &#x1f525;c系列專欄&#xff1a;C/C零基礎到精通 &#x1f525; 給大…

二.基礎篇: 面向對象進階

1. 基礎篇語法篇&#xff1a;一.基礎篇&#xff1a;基礎語法-CSDN博客 面向對象進階 本章主要學習內容&#xff1a; static繼承包&#xff0c;final&#xff0c;權限修飾符&#xff0c;代碼塊抽象類接口多態內部類 1. static static翻譯過來就是靜態的意思static表示靜態&am…

AI語音模型PaddleSpeech踩坑(安裝)指南

PaddleSpeech簡介 PaddleSpeech 是基于飛槳 PaddlePaddle 的語音方向的開源模型庫&#xff0c;用于語音和音頻中的各種關鍵任務的開發&#xff0c;包含大量基于深度學習前沿和有影響力的模型。 PaddleSpeech安裝步驟 提示&#xff1a;要找到一個合適的PaddleSpeech版本與pad…

STM32開發學習——使用 Cortex-M3M4M7 故障異常原因與定位

STM32開發學習——使用 Cortex-M3/M4/M7 故障異常原因與定位 文章目錄 STM32開發學習——使用 Cortex-M3/M4/M7 故障異常原因與定位文檔說明&#xff1a;官方參考文檔線上鏈接&#xff08;可在線閱讀與下載&#xff09;&#xff1a;故障異常處理程序HardFault優先級升級說明故障…

java項目之相親網站的設計與實現源碼(springboot+mysql+vue)

風定落花生&#xff0c;歌聲逐流水&#xff0c;大家好我是風歌&#xff0c;混跡在java圈的辛苦碼農。今天要和大家聊的是一款基于springboot的相親網站的設計與實現。項目源碼以及部署相關請聯系風歌&#xff0c;文末附上聯系信息 。 項目簡介&#xff1a; 相親網站的設計與實…

連升三級!openGauss單機版從2.1.0經停3.0.0升級至5.0.0

前言 如前文所述&#xff0c;我們的小demo項目起初安裝了openGauss的2.1.0版本&#xff0c;由于2.1.0不是長期維護&#xff08;LTS&#xff09;版本&#xff0c;所以要升級到5.0.0LTS。考慮到雖然是DEMO項目&#xff0c;但也有些體驗用戶&#xff0c;所以為了保障業務連續性&a…

2023版brupsuite專業破解安裝

安裝教程&#xff0c;分兩部分&#xff1a; 1、安裝java環境、參考鏈接JAVA安裝配置----最詳細的教程&#xff08;測試木頭人&#xff09;_java安裝教程詳細-CSDN博客 2、安裝2023.4版本brupsuite&#xff1a;參考鏈接 2023最新版—Brup_Suite安裝配置----最詳細的教程&…

Java---類和對象第一節

目錄 1.面向對象初步認識 1.1什么是面向對象 1.2面向對象和面向過程的區別 2.類的定義和使用 2.1簡單認識類 2.2類的定義格式 2.3類的實例化 2.4類和對象的說明 3.this關鍵字 3.1訪問本類成員變量 3.2調用構造方法初始化成員變量 3.3this引用的特性 4.對象的構造以…

一文弄懂 Linux 系統調用函數之 exec 函數族

目錄 簡介函數原型參數說明返回值函數區別使用示例采用參數列表傳遞參數&#xff0c;以 execl 為例采用參數數組傳遞參數&#xff0c;以 execv 為例調用 PATH 下可執行文件&#xff0c;以 execlp 為例使用新的環境變量給新進程&#xff0c;以 execle 為例 更多內容 簡介 exec …

【Java】/*方法的使用-快速總結*/

目錄 一、什么是方法 二、方法的定義 三、實參和形參的關系 四、方法重載 五、方法簽名 一、什么是方法 Java中的方法可以理解為C語言中的函數&#xff0c;只是換了個名稱而已。 二、方法的定義 1. 語法格式&#xff1a; public static 返回類型 方法名 (形參列表) { //方…

windows server 2019 安裝 docker環境

一、根據官方說明進行安裝 , 看起來過程相當簡單, 但問題還是有的 準備 Windows 操作系統容器 | Microsoft Learn // 一個 powershell 腳本&#xff0c;該腳本配置環境以啟用與容器相關的 OS 功能并安裝 Docker 運行時。 Invoke-WebRequest -UseBasicParsing "https://r…

【Docker】Ubuntu下Docker的基本使用方法與常用命令總結

【Docker】docker的基本使用方法 鏡像image與容器container的關系基本命令- 查看 Docker 版本- 拉取鏡像- 查看系統中的鏡像- 刪除某個鏡像- 列出當前 Docker 主機上的所有容器&#xff0c;包括正在運行的、暫停的、已停止的&#xff0c;以及未運行的容器- 列出當前 Docker 主機…

【信息系統項目管理師知識點速記】溝通管理:管理溝通

管理溝通是確保項目信息流通順暢的關鍵流程,涉及到信息的收集、生成、傳播、存檔、檢索、監管及最終處理,以促進項目團隊與利益相關者的有效互動。這一過程不僅關乎信息的發布,更側重于信息的恰當格式與精準送達,同時鼓勵利益相關者的積極參與,包括信息補充、澄清和討論。…