Commit 6136c8cd authored by captainwong's avatar captainwong

test stdutil

parent 02599859
#pragma once #pragma once
#include <vector>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
...@@ -18,11 +19,11 @@ inline bool is_contain(const C& c, const T& t) { ...@@ -18,11 +19,11 @@ inline bool is_contain(const C& c, const T& t) {
/** /**
* @brief Sub 是 All 的子集,返回 All 内 Sub 的补集 * @brief Sub 是 All 的子集,返回 All 内 Sub 的补集
* @note All 和 Sub 必须为同样类型的容器 * @note All 和 Sub 必须为同样类型的容器(不支持initializer-list)
*/ */
template <class C> template <class C>
inline C get_other(const C & All, const C& Sub) { inline C get_other(const C & All, const C& Sub) {
typename C res, tmp; C res, tmp;
std::copy(Sub.begin(), Sub.end(), std::back_inserter(tmp)); std::copy(Sub.begin(), Sub.end(), std::back_inserter(tmp));
for (const auto& i : All) { for (const auto& i : All) {
bool in_Sub = false; bool in_Sub = false;
...@@ -41,8 +42,7 @@ inline C get_other(const C & All, const C& Sub) { ...@@ -41,8 +42,7 @@ inline C get_other(const C & All, const C& Sub) {
} }
/** /**
* @brief Sub 是 All 的子集,返回 All 内 Sub 的补集 * @brief t 是 v 的子集,返回 v 内 t 的补集
* @note All 和 Sub 必须为同样类型的容器
*/ */
template <class V> template <class V>
std::vector<std::wstring> get_other(const V& v, const std::wstring& t) { std::vector<std::wstring> get_other(const V& v, const std::wstring& t) {
...@@ -51,6 +51,9 @@ std::vector<std::wstring> get_other(const V& v, const std::wstring& t) { ...@@ -51,6 +51,9 @@ std::vector<std::wstring> get_other(const V& v, const std::wstring& t) {
return ret; return ret;
} }
/**
* @brief t 是 v 的子集,返回 v 内 t 的补集
*/
template <class V> template <class V>
std::vector<std::string> get_other(const V& v, const std::string& t) { std::vector<std::string> get_other(const V& v, const std::string& t) {
std::vector<std::string> ret = {}; std::vector<std::string> ret = {};
......
...@@ -252,6 +252,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_mutex", "test_mutex\te ...@@ -252,6 +252,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_mutex", "test_mutex\te
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_threadpool", "test_threadpool\test_threadpool.vcxproj", "{96714588-A974-49B5-95BE-BF843FBFD260}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_threadpool", "test_threadpool\test_threadpool.vcxproj", "{96714588-A974-49B5-95BE-BF843FBFD260}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_stdutil", "test_stdutil\test_stdutil.vcxproj", "{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
...@@ -450,6 +452,14 @@ Global ...@@ -450,6 +452,14 @@ Global
{96714588-A974-49B5-95BE-BF843FBFD260}.Release|x64.Build.0 = Release|x64 {96714588-A974-49B5-95BE-BF843FBFD260}.Release|x64.Build.0 = Release|x64
{96714588-A974-49B5-95BE-BF843FBFD260}.Release|x86.ActiveCfg = Release|Win32 {96714588-A974-49B5-95BE-BF843FBFD260}.Release|x86.ActiveCfg = Release|Win32
{96714588-A974-49B5-95BE-BF843FBFD260}.Release|x86.Build.0 = Release|Win32 {96714588-A974-49B5-95BE-BF843FBFD260}.Release|x86.Build.0 = Release|Win32
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Debug|x64.ActiveCfg = Debug|x64
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Debug|x64.Build.0 = Debug|x64
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Debug|x86.ActiveCfg = Debug|Win32
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Debug|x86.Build.0 = Debug|Win32
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Release|x64.ActiveCfg = Release|x64
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Release|x64.Build.0 = Release|x64
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Release|x86.ActiveCfg = Release|Win32
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}.Release|x86.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
...@@ -500,6 +510,7 @@ Global ...@@ -500,6 +510,7 @@ Global
{B8F4AB37-A049-443B-8B75-4D0C831B234B} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F} {B8F4AB37-A049-443B-8B75-4D0C831B234B} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F}
{F1EFC4C7-AF79-4A65-9FE1-7C5305DC2E6A} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F} {F1EFC4C7-AF79-4A65-9FE1-7C5305DC2E6A} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F}
{96714588-A974-49B5-95BE-BF843FBFD260} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F} {96714588-A974-49B5-95BE-BF843FBFD260} = {D9BC4E5B-7E8F-4C86-BF15-CCB75CBC256F}
{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB} = {ABCB8CF8-5E82-4C47-A0FC-E82DF105DF99}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D} SolutionGuid = {A8EBEA58-739C-4DED-99C0-239779F57D5D}
......
#include "../../jlib/util/std_util.h"
int main()
{
std::vector<int> All{ 1, 2, 3,4,5 };
std::vector<int> Sub{ 1,2,3 };
auto other = jlib::get_other(All, Sub);
}
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{2457D30D-2DE9-4DF2-9047-CFA652E4F6CB}</ProjectGuid>
<RootNamespace>teststdutil</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="test_stdutil.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="test_stdutil.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment