C ++ 11等同于C ++ 14中引入的std :: quoted [英] C++11 equivalent to std::quoted introduced in C++14

查看:363
本文介绍了C ++ 11等同于C ++ 14中引入的std :: quoted的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

answer 中所使用的,我正在寻找与C ++ 11兼容的代码,但它们 std :: quoted 的使用使我无法实现这一目标。有人可以建议替代解决方案吗?

As used in this answer, I'm looking for a C++11 compatible code for the same but the usage of std::quoted prevents me from achieving that. Can anyone suggest an alternative solution?

推荐答案

我的回答是假设您希望找到一种通用的方法来处理这种情况。定义该准则的主要问题是:
对于较旧的编译器版本,我应将此代码维护多长时间?

I give my answer assuming that you expect to find a generic approach to handle such situations. The main question that defines the guideline for me is: "How long am I supposed to maintain this code for an older compiler version?"


  1. 如果我确定它将与其余代码库一起迁移到较新的工具集中(即使需要几年时间,但不可避免地会发生),那么我只是从我的编译器的下一个目标版本的标准标头复制粘贴实现,并将其放入 namespace std 的单独标头中代码库。即使这是一种非常粗鲁的技巧,它也可以确保我的代码版本与迁移后获得的代码版本完全相同。当我开始使用较新的(在这种情况下,与C ++ 14兼容)编译器时,我将仅删除自己的 quoted.h ,就是这样。

  1. If I'm certain that it will be migrated to the newer toolset along with the rest of the code base (even though in a few years time, but it will inevitably happen), then I just copy-paste implementation from the standard headers of the next target version of my compiler and put it into namespace std in a separate header within my code base. Even though it's a very rude hack, it ensures that I have exactly the same code version as the one I'll get after migration. As I start using newer (in this case C++14-compatible) compiler, I will just remove my own "quoted.h", and that's it.

重要警告 Barry建议复制并粘贴gcc的实现,我同意,只要 gcc 是您的主要目标编译器。如果不是这种情况,那么我将从您的编译器中获取一个。我之所以明确声明,是因为我在尝试将gcc的 std :: nested_exception 复制到我的代码库时遇到了麻烦,并且在从Visual Studio 2013切换到2017时发现几个差异。另外,在 gcc 的情况下,请注意其许可证。

Important Caveat: Barry suggested to copy-paste gcc's implementation, and I agree as long as the gcc is your main target compiler. If that's not the case, then I'd take the one from your compiler. I'm making this statement explicitly because I had troubles when I tried to copy gcc's std::nested_exception into my code base and, having switched from Visual Studio 2013 to 2017, noticed several differences. Also, in the case of gcc, pay attention to its license.


  1. 如果我必须在相当长一段时间内保持与该较旧编译器的兼容性(例如,如果我的产品针对的是多个编译器版本),那么首先查看是否Boost中有类似的功能。而且在大多数情况下都是这样。因此,请在Boost网站上> 。即使它声明

  1. If I'm in a situation where I'll have to maintain compatibility with this older compiler for quite a while (for instance, if my product targets multiple compiler version), then it's more preferable first of all to look if there's a similar functionality available in Boost. And there is, in most cases. So check out at Boost website. Even though it states




Boot $尚不接受引用字符串的I / O操纵器b $ b作为公共成分。因此,头文件当前位于

"Quoted" I/O Manipulators for Strings are not yet accepted into Boost as public components. Thus the header file is currently located in

中,您可以通过 boost / detail使用它。而且,我坚信它仍然比编写自己的版本更好(尽管 Synxis的建议),即使后者可能非常简单。

you are able to use it from "boost/detail". And, I strongly believe that it's still better than writing your own version (despite the advice from Synxis), even though the latter can be quite simple.


  1. 如果不得不维护旧的工具集,并且您不能使用Boost,那么...那么,值得考虑将您自己的实现放入其中。

  1. If you're obliged to maintain the old toolset and you cannot use Boost, well...then it's maybe indeed worth thinking of putting your own implementation in.

这篇关于C ++ 11等同于C ++ 14中引入的std :: quoted的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆