目标是使Feature标记系统没有运行时成本.一个简单的C99解决方案是:
C99:
#include <stdio.h>
#define flag_1 1
int main()
{
#if flag_1
printf("Active\n");
#else
printf("InActive\n");
#endif
return 0;
}
Run Code Online (Sandbox Code Playgroud)
并不是说这里的C++ 17解决方案看起来很优雅:
#include <iostream>
constexpr bool tag_flag_1 = true;
constexpr bool tag_flag_2 = true;
int main()
{
if constexpr(tag_flag_1)
{
std::cout << "Active" << std::endl;
}
else
{
std::cout << "InActive" << std::endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是因为"if constexpr"构造仅在"if"构造所在的位置有效,所以不起作用.例如,此代码无效:
if constexpr(tag_flag_1)
{
class foo
{
};
}
Run Code Online (Sandbox Code Playgroud)
而这一个是:
#if tag_flag_1
class foo
{
};
#endif
Run Code Online (Sandbox Code Playgroud)
C99解决方案有问题:
打字:
if constexpr(flag_not_exists) …Run Code Online (Sandbox Code Playgroud) 突然,今天早上我打开电脑,启动了视觉工作室...无论我尝试了什么,无论是运行还是调试,无论浏览器是什么(chrome/firefox/IE 11),它都在等待localhost永远.
如果我将它部署到azure,只需登录(持续集成)它就像一个魅力:http://couleur-emotion.azurewebsites.net/(我正在重建我的木乃伊绘画网站,以学习ASP.net MVC )
我读过两个:
在我写的时候,它一直在等待localhost超过15分钟.我重新启动了VS,甚至重新启动了计算机...尝试在Firefox上尝试ipv6禁用等等
我注意到(不知道它是否有用)用127.0.0.1替换localhost会抛出:
Bad Request - Invalid Hostname
HTTP Error 400. The request hostname is invalid.
Run Code Online (Sandbox Code Playgroud)
还有我的C:\ Windows\System32\drivers\etc\hosts(不变)
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in …Run Code Online (Sandbox Code Playgroud) 我正在使用subprocess.run()一些自动化测试.主要是自动执行:
dummy.exe < file.txt > foo.txt
diff file.txt foo.txt
Run Code Online (Sandbox Code Playgroud)
如果在shell中执行上述重定向,则这两个文件始终相同.但是无论何时file.txt太长,下面的Python代码都不会返回正确的结果.
这是Python代码:
import subprocess
import sys
def main(argv):
exe_path = r'dummy.exe'
file_path = r'file.txt'
with open(file_path, 'r') as test_file:
stdin = test_file.read().strip()
p = subprocess.run([exe_path], input=stdin, stdout=subprocess.PIPE, universal_newlines=True)
out = p.stdout.strip()
err = p.stderr
if stdin == out:
print('OK')
else:
print('failed: ' + out)
if __name__ == "__main__":
main(sys.argv[1:])
Run Code Online (Sandbox Code Playgroud)
这是以下C++代码dummy.cc:
#include <iostream>
int main()
{
int size, count, a, b;
std::cin >> size;
std::cin >> …Run Code Online (Sandbox Code Playgroud) 我正在阅读boost :: MPL作者的c ++模板元编程书.我是精神/凤凰图书馆的忠实粉丝.
但是我很想知道.使用c ++元编程模板是一件麻烦事.它不是用于那种用途.模板和宏都不支持循环.在模板中,您基本上必须通过递归.
据我了解,c ++编译过程大致如下:
模板元编程是对第1步和第2步的攻击,20年前被错误地发现了.
使用实际语言不是更简单吗?我的意思是一些语言可以访问c ++语法树并操纵它,以及良好的文本处理能力.
我正在考虑像twig/django这样的模板语言,以及g ++ AST的相应钩子,以及type_traits和pod类型的原生定义.
这存在吗?我在网上找不到这样的东西.它可以实现与c ++模板元编程相同的结果(以及更多),但编译速度更快,代码更清晰,更易读.
我已经阅读了几个相关的链接.
对于下载存档+"setup.py install"或"pip install pyscopg2"我都得到以下错误.我安装了visual studio 2012,我安装了一个2010版本来摆脱"找不到vcvarsall.bat"
错误:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python34\libs /LIBPATH:C:\Python34\PCbuild /LIBPATH:C:/PROGRA~1/POSTGR~1/9.3/lib ws2_32.lib advapi32.lib secur32.lib libpq.lib shfolder.lib build\temp.win32-3.4\Release\psycopg\psycopgmodule.obj build\temp.win32-3.4\Release\psycopg\green.obj build\temp.win32-3.4\Release\psycopg\pqpath.obj build\temp.win32-3.4\Release\psycopg\utils.obj build\temp.win32-3.4\Release\psycopg\bytes_format.obj build\temp.win32-3.4\Release\psycopg\connection_int.obj build\temp.win32-3.4\Release\psycopg\connection_type.obj build\temp.win32-3.4\Release\psycopg\cursor_int.obj build\temp.win32-3.4\Release\psycopg\cursor_type.obj build\temp.win32-3.4\Release\psycopg\diagnostics_type.obj build\temp.win32-3.4\Release\psycopg\error_type.obj build\temp.win32-3.4\Release\psycopg\lobject_int.obj build\temp.win32-3.4\Release\psycopg\lobject_type.obj build\temp.win32-3.4\Release\psycopg\notify_type.obj build\temp.
win32-3.4\Release\psycopg\xid_type.obj build\temp.win32-3.4\Release\psycopg\adapter_asis.obj build\temp.win32-3.4\Release\psycopg\adapter_binary.obj build\temp.win32-3.4\Release\psycopg\adapter_datetime.obj build\temp.win32-3.4\Release\psycopg\adapter_list.obj build\temp.win32-3.4\Release\psycopg\adapter_pboolean.obj build\temp.win32-3.4\Release\psycopg\adapter_pdecimal.obj build\temp.win32-3.4\Release\psycopg\adapter_pint.obj build\temp.win32-3.4\Release\psycopg\adapter_pfloat.obj build\temp.win32-3.4\Release\psycopg\adapter_qstring.obj build\temp.win32-3.4\Release\psycopg\microprotocols.obj build\temp.win32-3.4\Release\psycopg\microprotocols_proto.obj build\temp.win32-3.4\Release\psycopg\typecast.obj /OUT:build\lib.win32-3.4\psycopg2\_psycopg.pyd /IMPLIB:build\temp.win32-3.4\Release\psycopg\_psycopg.lib /MANIFESTFILE:build\temp.win32-3.4\Release\psycopg\_psycopg.pyd.manifest
Creating library build\temp.win32-3.4\Release\psycopg\_psycopg.lib and object build\temp.win32-3.4\Release\psycopg\_psycopg.exp
pqpath.obj : error LNK2019: unresolved external symbol _PQclear referenced in function _pq_raise …Run Code Online (Sandbox Code Playgroud) 我尽可能地减少代码以保持 代码sscce这段代码的作用:
CreateProcess TerminateProcess在我们得到的把手上杀了记事本CreateProcess.TerminateProcess是异步OpenProcess给死去的pid您可以在调试中轻松检查(在OpenProcess之前),在任务管理器或processExplorer中找不到给定的Pid.但没有其他Windows API函数似乎接受这个Pid
#include "stdafx.h"
#include <windows.h>
#include "Psapi.h"
#include <TlHelp32.h>
#include <iostream>
#include <cassert>
typedef unsigned long PID;
typedef const std::string& P_PATH;
// Launch an executable given by a path and set a few infomatives stuffs passed as ref parameters
bool launch_process(P_PATH path, STARTUPINFO& info, PROCESS_INFORMATION& processInfo, HANDLE& hProcess, PID& pid)
{
setlocale(LC_ALL, "en_US.utf8");
std::wstring widestr = std::wstring(path.begin(), path.end());
const wchar_t* widecstr …Run Code Online (Sandbox Code Playgroud) 使用此代码:
from lxml import etree
with open( 'C:\\Python33\\projects\\xslt', 'r' ) as xslt, open( 'C:\\Python33\\projects\\result', 'a+' ) as result, open( 'C:\\Python33\\projects\\xml', 'r' ) as xml:
s_xml = xml.read()
s_xslt = xslt.read()
transform = etree.XSLT(etree.XML(s_xslt))
out = transform(etree.XML(s_xml))
result.write(out)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
from projects.xslt_transform import trans
File ".\projects\xslt_transform.py", line 17, in <module>
transform = etree.XSLT(etree.XML(s_xslt))
File "xslt.pxi", line 409, in lxml.etree.XSLT.__init__ (src\lxml\lxml.etree.c:150256)
lxml.etree.XSLTParseError: Invalid expression
Run Code Online (Sandbox Code Playgroud)
这对xml/xslt文件可以与其他工具一起使用.
此外,我必须摆脱两个文件的顶部声明中的编码属性,以便不获取:
ValueError: Unicode strings with encoding declaration …Run Code Online (Sandbox Code Playgroud) 我有一个小测试项目,我总是在我的开发应用程序之前安装和测试包.由于我在其上安装了django调试工具栏,因此在连接到管理站点时出现以下错误消息(其他网址很好):
NoReverseMatch at /admin/
Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': 'auth'}' not found. 0 pattern(s) tried: []
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.8
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'app_list' with arguments '()' and keyword arguments '{'app_label': 'auth'}' not found. 0 pattern(s) tried: []
Exception Location: C:\Anaconda\lib\site-packages\django-1.8-py2.7.egg\django\core\urlresolvers.py in _reverse_with_prefix, line 436
Python Executable: C:\Anaconda\python.exe
Python Version: 2.7.6
Python Path:
['C:\\Users\\ut1u3h\\test_project',
'C:\\Anaconda\\lib\\site-packages\\django-1.8-py2.7.egg',
'C:\\Anaconda\\lib\\site-packages\\django_rosetta-0.7.5-py2.7.egg',
'C:\\Anaconda\\lib\\site-packages\\django_debug_toolbar-1.1-py2.7.egg',
'C:\\Anaconda\\lib\\site-packages\\sqlparse-0.1.11-py2.7.egg',
'C:\\Anaconda\\python27.zip',
'C:\\Anaconda\\DLLs',
'C:\\Anaconda\\lib',
'C:\\Anaconda\\lib\\plat-win',
'C:\\Anaconda\\lib\\lib-tk',
'C:\\Anaconda', …Run Code Online (Sandbox Code Playgroud) 我读:
代码段:
HANDLE hProcess = OpenProcess(SYNCHRONIZE, TRUE, inProcessID);
if (NULL == hProcess)
{
WaitForSingleObject(hProcess,INFINITE);
}
Run Code Online (Sandbox Code Playgroud)
我试过WaitForSingleObject和WaitForSingleObjectEx,既没有实际的等待.
例如,假设记事本正在运行,我想等待一些用户关闭它.我该怎么办 ?
c++ ×5
python ×3
python-3.x ×2
winapi ×2
asp.net ×1
django ×1
iis ×1
lxml ×1
postgresql ×1
process ×1
subprocess ×1
xml ×1
xslt ×1