Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 用户库应该在哪些NS中?_C++_Namespaces_Shared Libraries - Fatal编程技术网

C++ 用户库应该在哪些NS中?

C++ 用户库应该在哪些NS中?,c++,namespaces,shared-libraries,C++,Namespaces,Shared Libraries,这是我问题的继续: 我正在将自定义库代码移动到命名空间工具箱中——包括包含模板和开始和结束,用于CStringA和CStringW 我有一个无模板函数算法“contains”: 命名空间工具箱{ 模板 bool包含(常量集合类型和集合、常量元素类型和元素、比较函数类型和比较函数) { 使用namespace::std; return end(collection)!=find_if(begin(collection),end(collection),[&](const元素类型和候选者){返回比较

这是我问题的继续:

我正在将自定义库代码移动到
命名空间工具箱中
——包括
包含
模板和
开始
结束
,用于
CStringA
CStringW

我有一个无模板函数算法“contains”:

命名空间工具箱{
模板
bool包含(常量集合类型和集合、常量元素类型和元素、比较函数类型和比较函数)
{
使用namespace::std;
return end(collection)!=find_if(begin(collection),end(collection),[&](const元素类型和候选者){返回比较函数(候选者,元素);};
}
}//NS
这适用于以下情况,或根据范围内的内容(以下为全球NS),适用于以下情况失败:

static const TCHAR*kPackFiles[]={{u T(“boxit”),{u T(“pack”)};
const auto&name=filename.GetName();
if(包含(kPackFiles,name,Toolbox::不区分大小写\u equal\u to())
做些有趣的事;
除非以下内容在范围内,否则上述内容将编译:

namespace Toolbox {
template <typename T>
const typename ::std::enable_if<::std::is_same<T, CStringA>::value || ::std::is_same<T, CStringW>::value, T>::type::XCHAR *
    begin(const T & str) { return str.GetString(); }

template <typename T>
const typename ::std::enable_if<::std::is_same<T, CStringA>::value || ::std::is_same<T, CStringW>::value, T>::type::XCHAR *
    end(const T & str) { return str.GetString() + str.GetLength(); }
} // NS Toolbox
命名空间工具箱{
模板
const typename::std::enable_if::type::XCHAR*
begin(const T&str){return str.GetString();}
模板
const typename::std::enable_if::type::XCHAR*
end(const T&str){return str.GetString()+str.GetLength();}
}//NS工具箱

上述内容旨在扩展
CStringA
CStringW
以在其上提供
const char\u type
迭代器。这通常适用于其他场景,例如
(c:my_cstring)的cout内容和名称空间的名称更是一个自以为是的问题。对于如何确定名称空间的内容,人们有不同的看法。我需要“工作系统”——我似乎没有把握全局,而NS对我来说根本就不是一种直观的方式。好吧,我误解了。那么,你们中的任何人是如何在一个框架中看到它的,从而使它真正为你们工作的呢?(或者如果我错了,我只是得到了enable_)?名称空间的内容和名称更是一个自以为是的问题。对于如何确定名称空间的内容,人们有不同的看法。我需要“工作系统”——我似乎没有把握全局,而NS对我来说根本就不是一种直观的方式。好吧,我误解了。那么,你们中的任何人是如何在一个框架中看到它的,从而使它真正为你们工作的呢?(或者,如果错误,我只是得到了enable_)?
static const TCHAR * kPackFiles[] = { _T("boxit"), _T("pack") };
const auto & name = filename.GetName();
if (contains(kPackFiles, name, Toolbox::case_insensitive_equal_to<Toolbox::TCHARStringPolicy>()))
    do_something_interesting();
namespace Toolbox {
template <typename T>
const typename ::std::enable_if<::std::is_same<T, CStringA>::value || ::std::is_same<T, CStringW>::value, T>::type::XCHAR *
    begin(const T & str) { return str.GetString(); }

template <typename T>
const typename ::std::enable_if<::std::is_same<T, CStringA>::value || ::std::is_same<T, CStringW>::value, T>::type::XCHAR *
    end(const T & str) { return str.GetString() + str.GetLength(); }
} // NS Toolbox