有没有办法将std :: bind绑定到std :: weak_ptr?我想存储一个"弱函数"回调,当被调用者被销毁时,它会自动"断开连接".
我知道如何使用shared_ptr创建一个std :: function:
std::function<void()> MyClass::GetCallback()
{
return std::function<void()>(std::bind(&MyClass::CallbackFunc, shared_from_this()));
}
Run Code Online (Sandbox Code Playgroud)
但是返回的std :: function使我的对象永远保持活着.所以我想将它绑定到weak_ptr:
std::function<void()> MyClass::GetCallback()
{
std::weak_ptr<MyClass> thisWeakPtr(shared_from_this());
return std::function<void()>(std::bind(&MyClass::CallbackFunc, thisWeakPtr));
}
Run Code Online (Sandbox Code Playgroud)
但那不编译.(std :: bind将不接受weak_ptr!)有没有办法绑定到weak_ptr?
我已经找到了关于这个的讨论(见下文),但似乎没有标准的实现.存储"弱功能"的最佳解决方案是什么,特别是如果Boost不可用?
讨论/研究(所有这些都使用Boost并且没有标准化):
在处理这个问题的过程中,我注意到GCC(v4.7)的实现std::function在它们被值出现时会移动它的论点.以下代码显示了此行为:
#include <functional>
#include <iostream>
struct CopyableMovable
{
CopyableMovable() { std::cout << "default" << '\n'; }
CopyableMovable(CopyableMovable const &) { std::cout << "copy" << '\n'; }
CopyableMovable(CopyableMovable &&) { std::cout << "move" << '\n'; }
};
void foo(CopyableMovable cm)
{ }
int main()
{
typedef std::function<void(CopyableMovable)> byValue;
byValue fooByValue = foo;
CopyableMovable cm;
fooByValue(cm);
}
// outputs: default copy move move
Run Code Online (Sandbox Code Playgroud)
我们在这里看到cm执行的副本(这似乎是合理的,因为byValue's参数是按值获取的),但是有两个动作.由于它function是在副本上运行cm,它移动其参数的事实可以被视为一个不重要的实现细节.但是,与以下一起使用时functionbind …
我正在使用带有BIND 10.1.2的Linux CentOS 6.64
我在主DNS(example.com)中有一个额外的区域(list.example.com)
绑定(命名)配置文件/etc/named.conf包含区域:
zone "list.example.com" IN {
type master;
file "list-example-com.zone";
allow-query { localhost; };
allow-transfer { 127.0.0.1; };
};
Run Code Online (Sandbox Code Playgroud)
区域文件list-example-com.zone如下:
$TTL 86400 ; 1 day
@ IN SOA ns1.example.com. hostmaster.example.com. (
2004032201 ; serial
7200 ; refresh (2 hours)
5400 ; retry (1.5 hours)
1814400 ; expire (3 weeks)
86400 ; minimum (1 day)
)
IN NS ns1.example.com.
;
IN A 192.168.177.22
;
; -----------------------------------------------------------------
49.30.22.66 IN A 127.0.0.3
44.63.20.10 IN A 127.0.0.2
64.42.10.5 IN A …Run Code Online (Sandbox Code Playgroud) 我在使用多个jQuery绑定数千个元素和输入时遇到加载速度问题,有没有更有效的方法呢?
该站点具有通过ajax调用在产品列表之间切换的能力,页面无法刷新.有些列表有10个项目,大约100个,有些超过2000个.当我开始在列表之间翻转时出现速度问题; 每次加载2000+项目列表时,系统拖动大约10秒钟.
在重建列表之前,我将目标元素的html设置为'',并取消绑定下面的两个绑定.我确定它与我在回调中所做的所有父,子和子调用有关.任何帮助深表感谢.
循环2500次
<ul>
<li><input type="text" class="product-code" /></li>
<li>PROD-CODE</li>
...
<li>PRICE</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
结束循环
$('li.product-code').bind( 'click', function(event){
selector = '#p-'+ $(this).prev('li').children('input').attr('lm');
$(selector).val(
( $(selector).val() == '' ? 1 : ( parseFloat( $(selector).val() ) + 1 ) )
);
Remote.Cart.lastProduct = selector;
Remote.Cart.Products.Push(
Remote.Cart.customerKey,
{
code : $(this).prev('li').children('input').attr('code'),
title : $(this).next('li').html(),
quantity : $('#p-'+ $(this).prev('li').children('input').attr('lm') ).val(),
price : $(this).prev('li').children('input').attr('price'),
weight : $(this).prev('li').children('input').attr('weight'),
taxable : $(this).prev('li').children('input').attr('taxable'),
productId : $(this).prev('li').children('input').attr('productId'),
links : $(this).prev('li').children('input').attr('productLinks')
},
'#p-'+ $(this).prev('li').children('input').attr('lm'),
false,
( parseFloat($(selector).val()) - 1 ) …Run Code Online (Sandbox Code Playgroud) 我正在使用sqlite.org上提供的sqlite3库.
我有一些我想要存储在数据库中的unsigned longs.我不想自己构建查询并将其保持开放以进行某种注入(无论是否是偶然的).因此,我正在使用这些sqlite_bind_*函数来"清理"我的参数.
问题是对于无符号长整数,只有整数没有函数类型.
int sqlite3_bind_int(sqlite3_stmt*, int, int);
int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64);
如果我无法以无符号方式存储它们,我肯定会有数字会溢出.
我自己需要自己管理吗?(即在插入数据库之前从db中选择或转换为signed类型后转换为无符号类型)
如果我自己必须自己管理,当比较真的意味着在无符号范围内时,如何做一些存储为有符号长整数的比较查询?
查看转换后的INTEGER数据类型,可以认为无符号长整数可以毫无问题地表示.
如果有其他可用解决方案,请赐教!谢谢!
给出以下HTML:
<form>
<input type="number" required>
</form>
Run Code Online (Sandbox Code Playgroud)
以下javascript工作正常:
(function( jQuery ) {
jQuery("input").bind("invalid", function(event) {
console.log(event.type);
});
})( jQuery );
Run Code Online (Sandbox Code Playgroud)
但是这个javascript代码没有:
(function( jQuery ) {
jQuery("form").on("invalid", "input", function(event) {
console.log(event.type);
});
})( jQuery );
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么?
编辑:更正小提琴纠正一个:http://jsfiddle.net/PEpRM/1
这是第一个问题,但我已经有一段时间了.
我有什么:
我正在构建一个播放音频流和在线播放列表的Android应用.一切都工作正常,但我在与我的服务沟通时遇到问题.
音乐正在服务中播放,以startForeground开头,所以它不会被杀死.
我需要通过我的活动与服务进行沟通,以获取曲目名称,图像和更多内容.
我的问题是什么:
我想我需要使用bindService(而不是我当前的startService)启动我的服务,以便活动可以与它通信.
但是,当我这样做时,我的服务在关闭Activity后被杀死.
我怎样才能得到这两个?绑定和前台服务?
谢谢!
'我想将RichTextBox的Height属性绑定到GridView的Row的Height属性.我怎样才能做到这一点?我不知道如何获得Row的高度,因为我无法访问xaml中的Row,我想做什么.
Ancestor类型应该是GridViewHeaderRow,但我不知道它的级别......
编辑:
<my:RadGridView Height="524" RowHeight="300" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn DataMemberBinding="{Binding SchoolclassName}" Header="Schoolclass" Width="0.1*" />
<my:GridViewDataColumn DataMemberBinding="{Binding SubjectName}" Header="Subject" Width="0.1*" />
<my:GridViewDataColumn Width="0.3*" Header="Homework">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=dataGrid1,Path=RowHeight}" >
<FlowDocument>
<Paragraph>
<Run Text="{Binding Homework}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
<my:RadGridView Height="524" ItemsSource="{Binding Lessons}" AutoGenerateColumns="False" Name="dataGrid1" VerticalAlignment="Top" SelectionMode="Single" CanUserSortColumns="False" IsFilteringAllowed="False">
<my:RadGridView.Columns>
<my:GridViewDataColumn Name="ContentColumn" Width="0.3*" Header="Content">
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<RichTextBox Height="{Binding ElementName=MyRowNameToBindTo,Path=Height}">
<FlowDocument>
<Paragraph>
<Run Text="{Binding Content}"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
Run Code Online (Sandbox Code Playgroud)
...
在Mozilla开发人员中心,有一个关于该Function.prototype.bind功能的页面,并为不支持此功能的浏览器提供兼容性功能.
但是,在分析此兼容性代码时,我无法找出它们使用的原因instanceof nop.nop已经设定为function() {}.ECMA规范的哪一部分与bind此相对应?什么变量是一个实例function() {}?
以下返回false,因此我不完全知道它的用途.在做instanceof function() {}检查时会发生什么事情?
(function() {}) instanceof (function() {}) // false
Run Code Online (Sandbox Code Playgroud)
代码如下:
Function.prototype.bind = function( obj ) {
if(typeof this !== 'function')
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
var slice = [].slice,
args = slice.call(arguments, 1),
self = this,
nop = function () {},
bound = function () {
return self.apply( this instanceof …Run Code Online (Sandbox Code Playgroud) 如何在WPF XAML中绑定到System.Drawing.Printing.PrinterSettings.InstalledPrinters列表,这是一个静态StringCollection.例如,要在ComboBox中使用它,用户可以选择要使用的打印机.