是否可以制作自定义操作符,以便您可以执行此类操作?
if ("Hello, world!" contains "Hello") ...
Run Code Online (Sandbox Code Playgroud)
注意:这是一个单独的问题:"这是一个好主意......";)
我经常想知道为什么C++的名字wchar_t不是简单的wchar,而且我从来没有找到答案.搜索引擎没有帮助,因为他们认为我在询问Windows的WCHAR类型.有任何想法吗?
我讨厌拥有一堆"左/右"方法.每次添加或删除属性时,我都必须修复每个方法.而代码本身看起来......错了.
public Foo(Foo other)
{
this.Bar = other.Bar;
this.Baz = other.Baz;
this.Lur = other.Lur;
this.Qux = other.Qux;
this.Xyzzy= other.Xyzzy;
}
Run Code Online (Sandbox Code Playgroud)
实际上,这只是一个展开的循环,它遍历属性,在对象之间复制它们.那么为什么不对这个事实说实话呢?反思救援!
public Foo(IFoo other)
{
foreach (var property in typeof(IFoo).GetProperties())
{
property.SetValue(this, property.GetValue(other, null), null);
}
}
Run Code Online (Sandbox Code Playgroud)
我可能只是试图强迫我从Lua学习到C#的范例,但这个特殊的例子对我来说似乎并不太臭.从这里开始,我开始做一些对字段顺序敏感的更复杂的事情.例如,我不是用一堆几乎相同的if语句来组成字段中的字符串,而是按照所需的顺序迭代它们:
public override string ToString()
{
var toJoin = new List<string>();
foreach (var property in tostringFields)
{
object value = property.GetValue(this, null);
if (value != null)
toJoin.Add(value.ToString());
}
return string.Join(" ", toJoin.ToArray());
}
private static readonly PropertyInfo[] tostringFields =
{
typeof(IFoo).GetProperty("Bar"), …Run Code Online (Sandbox Code Playgroud) 花了一些时间在Haskell和其他函数式语言中玩,我开始意识到设计的简单性来源于描述一般问题.虽然模板编程的许多方面可能远非简单,但有些用法很常见,我认为它们不会妨碍清晰度(尤其是函数模板).我发现模板通常可以简化当前设计,同时自动添加一些未来阻力.为什么他们的功能应该降级为图书馆作家?
另一方面,有些人似乎避免像瘟疫这样的模板.十年前,当泛型类型的概念对于大多数编程社区而言是陌生的时候,我能理解这一点.但是现在所有流行的静态类型OO语言都支持这种或那种形式的泛型.增加的熟悉程度似乎需要调整保守态度.
我最近向我表达了一种这样的保守态度:
你永远不应该做出比必要更通用的东西 - 软件开发的基本规则.
我真的很惊讶地看到这种说法如此夸张,好像应该是不言自明的.就个人而言,我发现它远非不言自明,对于像Haskell这样的语言,除非你另有说明,否则一切都是通用的.话虽如此,我想我明白这种观点来自哪里.
在我的脑海里,我确实有类似的规则在喋喋不休.现在它处于最前沿,我意识到我总是根据整体架构来解释它.例如,如果您有一个类,则不希望使用您可能有一天使用的大量功能加载它.如果你只需要一个具体的版本,就不要费心去做接口(虽然可模拟性可能是对这个版本的反驳).像这样的东西...
然而,我不做的是在微观层面上应用这一原则.如果我有一个小实用程序函数,没有理由依赖任何特定类型,我将创建一个模板.
所以你觉得怎么样?您认为过度概括是什么?根据具体情况,此规则是否具有不同的适用性?你甚至同意这是一个规则吗?
在iOS 7.1之后,如果我们想要通过空中部署我们的企业应用程序,manifest.plist文件的URL 必须是HTTPS.
例如:
itms-services://?action=download-manifest&url=https://example.com/manifest.plist
Run Code Online (Sandbox Code Playgroud)
在我的服务器中,我使用自签名SSL证书.当我点击iPhone上的URL时,它会显示Could not connect to <ip-address>并记录典型的
NSUnderlyingError=0x15d37040 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be `<ip-address>`, which could put your confidential information at risk.
Run Code Online (Sandbox Code Playgroud)
所以,我想知道我是否可以使用自签名SSL证书?
如果可以,我如何解决我遇到的问题?
我正在尝试使用SqlBulkCopy将一堆数据导入我们的网站.在大多数其他领域,我们使用的是Entity模型,它使用字节数组来表示SQL中的二进制数据.但是,SqlBulkCopy似乎使byte []与字符串混淆.除了抛出异常的一个二进制列之外,一切似乎都工作正常:"数据源中String类型的给定值无法转换为指定目标列的二进制类型."
我创建了一个小测试用例来说明问题:
using System.Data;
using System.Data.SqlClient;
namespace SqlBulkCopyTest
{
class Program
{
static void Main(string[] args)
{
DataTable table = new DataTable("BinaryData");
table.Columns.Add("Data");
for (int i = 0; i < 10; i++)
{
var row = table.NewRow();
row["Data"] = new byte[5] { 1, 2, 3, 4, 5 };
table.Rows.Add(row);
}
using (var connection =
new SqlConnection("Data Source=localhost\\sqlexpress;Initial Catalog=TestBulkCopy;Integrated Security=True"))
{
connection.Open();
using (var copier = new SqlBulkCopy(connection))
{
copier.DestinationTableName = table.TableName;
/* EXCEPTION HERE: */ copier.WriteToServer(table);
}
}
} …Run Code Online (Sandbox Code Playgroud) 有无数文章和博客讨论C++ 最令人烦恼的解析,但我似乎找不到比"C++文献"更具实质性的参考文献.
这个词从哪里来的?
我在头文件中定义了一个结构,如下所示:
#define LC_ERR_LEN 300
typedef struct dLC_ERRMSG {
short nr;
short strategy;
char tx[LC_ERR_LEN];
} LC_ERRMSG;
Run Code Online (Sandbox Code Playgroud)
我在我的代码中使用的是:
LC_ERRMSG err;
char *szError;
szError = strerror(sStatus);
snprintf(err.tx,LC_ERR_LEN," %s - %s",szFilename,szError);
/* do something with our error string */
Run Code Online (Sandbox Code Playgroud)
这样可行.但是,如果我LC_ERRMSG err;全局声明- 即在使用它的函数之外,或者甚至extern LC_ERRMSG err;(这是我的初衷,因为我希望能够在中心位置读出错误状态),snprintf调用的代码段错误.
你能告诉我任何线索吗?
ddd告诉我,当全局声明时,内存被初始化为全零,或者在声明为extern时至少初始化和可读.值szFilename,szError和LC_ERR_LEN都是正确且有意义的.
我有一个boost :: multi_index_container,由ordered_non_unique键索引并按顺序排列.当我遍历非唯一索引时,条目按照它们被添加到容器的顺序而不是它们在序列中的位置出现.
如何设置非唯一索引以保留插入顺序?我尝试使用ordered_non_unique创建一个composite_key并对其进行排序,但由于sequenced不是键控索引,因此它不能编译.
这是一个最小的例子(这里的实时版本):
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/sequenced_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/member.hpp>
#include <iostream>
#include <vector>
using namespace boost::multi_index;
using namespace std;
struct Entry {
int nonUniqueInt;
string somethingExtra;
};
using Container_t = multi_index_container<Entry, indexed_by<
sequenced<>,
ordered_non_unique<
// ***** What can I put here? *****
member<Entry, int, &Entry::nonUniqueInt>
>
>>;
std::vector<Entry> const sampleData{
{1, "first"}, {2, "second"}, {3, "third"}, {3, "fourth"}, {2, "fifth"}, {1, "sixth"}
};
// fillFront should make the sequence LIFO
template <typename T>
void …Run Code Online (Sandbox Code Playgroud) 我使用GDB来调试Python和C的组合程序.当程序的分段错误发生时,GDB给出了一个错误.
81 ../sysdeps/unix/syscall-template.S: No such file or directory.
Run Code Online (Sandbox Code Playgroud)
这里有几行引用信息.
0 0x00007ffff6f2b6d7 in kill () at ../sysdeps/unix/syscall-template.S:81
1 0x000000000042a241 in posix_kill.64590 (self=<optimized out>, args=<optimized out>) at ../Modules/posixmodule.c:4306
2 0x000000000050e78c in call_function (oparg=<optimized out>, pp_stack=0x7fffffffd7b0) at ../Python/ceval.c:4020
3 PyEval_EvalFrameEx (f=f@entry=Frame 0x7ffff5784608, for file /usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py, line 121, in python_reloader (main_func=<instancemethod at remote 0x7ffff69a3a00>, args=(), kwargs={'use_static_handler': True, 'settings': None, 'pythonpath': None, 'verbosity': '1', 'traceback': None, 'use_ipv6': False, 'use_threading': True, 'use_reloader': True, 'insecure_serving': False}, exit_code=-11),
throwflag=throwflag@entry=0) at ../Python/ceval.c:2666
Run Code Online (Sandbox Code Playgroud)
这是GDB或我的程序的错误吗?我在跟踪信息中找不到任何我的程序类.
谢谢 !
c++ ×6
c ×2
c# ×2
templates ×2
terminology ×2
.net ×1
boost ×1
database ×1
enterprise ×1
extern ×1
gdb ×1
ios ×1
operators ×1
printf ×1
python ×1
refactoring ×1
reflection ×1
sql ×1
struct ×1