我想知道你们是否知道c ++关联映射容器类型,我可以执行多个键查找.地图需要有恒定的时间查找,但我不在乎它是有序还是无序.它只需要快速.
例如,我想在地图中存储一堆std :: vector对象,其中包含整数和void*作为查找键.int和void*都必须匹配我要检索的向量.有这样的事情吗?或者我将不得不自己动手.如果有,有什么建议吗?我一直在尝试将boost :: unordered_map存储在另一个boost :: unordered_map中,但我还没有使用此方法取得任何成功.如果没有更简单的方法,也许我会继续使用这种方法.谢谢!
我试图使用jQuery UI框架重新排序动态创建的CKEditors列表,但我遇到了编辑器释放的问题.当我刚刚使用a时<textarea>,它工作得很好,但现在,在拖动操作完成后,它不会让用户写任何文本.
这是Javascript代码:
$(function() {
$("#list").sortable({
placeholder: 'ui-state-highlight'
});
$("#list").disableSelection();
for (i=0;i<10;i++)
{
addEditor();
}
});
function addEditor()
{
alert("Hello");
var editor_fields = document.editors.elements["editor[]"];
var editorAmount = 0;
if (editor_fields.length)
{
editorAmount = editor_fields.length;
}
else
{
editorAmount = 1;
}
var newElem = $('#editor_container' + editorAmount).clone().attr('id', 'editor_container' + (editorAmount + 1));
newElem.html("<textarea class='editor' name='editor[]' id='editor" + (editorAmount + 1) + "' rows='4' cols='30'></textarea>");
$("#editor_container" + editorAmount).after(newElem);
$("#editor" + (editorAmount + 1)).ckeditor();
}
Run Code Online (Sandbox Code Playgroud)
这是HTML代码:
<form name="editors">
<ul id="list"> …Run Code Online (Sandbox Code Playgroud) 我在本地Git存储库中合并了两个分支,但存在一堆冲突.认为TortoiseGit上下文菜单中的"Resolve"将带我进入冲突解决GUI,我点击它 - 只是为了意识到我只是将所有冲突标记为已解决,而没有对它们做任何事情.因此,我有一堆未标记的文件:
master<<<<<<<<<
some change
=======
some other change
>>>>>>>>>>branch
Run Code Online (Sandbox Code Playgroud)
构造在其中,Git不知道它们仍然是一个问题.
如何将此冲突标记撤消为已解决,即再次将其标记为冲突?
一段时间后,我仍然遇到在FancyBox2中调整iframe高度的问题.我在父母那里打电话给我:
$(document).ready(function() {
$('.fancybox').fancybox();
$('.showframe').fancybox({
openEffect : 'elastic',
closeEffect : 'elastic',
beforeShow: function(){
this.width = ($('.fancybox-iframe').contents().find('body').width());
this.height = ($('.fancybox-iframe').contents().find('body').height());
},
afterClose : function() {
location.reload();
return;
},
onUpdate : { autoHeight: true},
helpers : {
overlay : {closeClick: false}
}
});
});
Run Code Online (Sandbox Code Playgroud)
当iframe打开时它可以正常工作,但在iframe中我有一个脚本,允许用户上传图像并显示上传图像的预览,因此iframe的高度会发生变化(取决于上传的照片数量),但是FancyBox不会"调整高度".我在我的"子"iframe中使用它来触发调整大小:
...some functions here that handle image upload and image display...
parent.$.fancybox.scrollBox();
Run Code Online (Sandbox Code Playgroud)
现在这仅适用于Firefox,而Chrome和IE将显示滚动条而不是调整iframe高度.有没有办法使这种跨浏览器兼容?
编辑:我得到这个代码在所有浏览器中工作:
parent.$('.fancybox-inner').height($('#wrap').height()+20);
Run Code Online (Sandbox Code Playgroud)
但问题是iframe不会居中(它只会调整高度,但不会重新居中于屏幕).我已经尝试了parent.$.fancybox.center();, parent.$.fancybox.reize();而且parent.$.fancybox.update();什么不是,但这只适用于Firefox.
我发现(纯粹的运气)这实际上适用于所有浏览器(甚至是IE8):
parent.$('.fancybox-inner').height($('#wrap').height()+30);
parent.$.fancybox.reposition();
Run Code Online (Sandbox Code Playgroud) 在我的C++程序中,我试图按值而不是按键对我的地图进行排序.
从这个问题来看,似乎很清楚,这样做的方法是创建一个集合,其元素是成对的,并且由我自己的less-than函数排序.
这是一些示例代码,我尝试这样做:
#include <map>
#include <set>
#include <iostream>
#include <string>
using namespace std;
bool compareCounts(const pair<string, size_t> &lhs, const pair<string, size_t> &rhs);
int main (int argc, char *argv[]) {
map <string, size_t> counter = { {"A", 1}, {"B", 2}, {"C", 3} };
set <pair<string, size_t>, decltype(compareCounts) *> sorted_counter;
for (map<string, size_t>::iterator it = counter.begin(); it != counter.end(); ++it) {
cout << "About to add: " << it->first << ":" << it->second << endl;
auto ret = sorted_counter.insert(*it); …Run Code Online (Sandbox Code Playgroud) 我的问题如下:我想将两个(不多)不同的数据类型作为值放入映射中.
typeX A, B, ...;
typeY Z, Y, ...;
void func (typeX) { ... }
void func (typeY) { ... }
std::map <std::string, what_to_put_here??> map;
map["a"] = A;
map["z"] = Z;
...
std::vector<std::string> list;
// This list will be something like "a", "y", ...
for (unsigned int i = 0; i < list.size(); ++i)
func( map[list[i]] )
Run Code Online (Sandbox Code Playgroud)
显然这不起作用,因为地图只接受一种数据类型的值.当循环"list"时,对"func"的调用应该是明确的,因为map [list [i]]的类型是已知的.
我想避免显式转换或类型检查,即......
if (typeid( map[list[i]] ).name() == "typeX")
func( map[list[i]] )
else if (typeid( map[list[i]] ).name() == "typeY")
func( map[list[i]] ) …Run Code Online (Sandbox Code Playgroud) 我在尝试使用NumPy计算IPython中的均方根误差时遇到问题.我很确定该函数是正确的,但是当我尝试输入值时,它会给我以下TypeError消息:
TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
import numpy as np
def rmse(predictions, targets):
return np.sqrt(((predictions - targets) ** 2).mean())
print rmse((2,2,3),(0,2,6))
Run Code Online (Sandbox Code Playgroud)
显然我的输入有问题.在我将数组放入rmse():生产线之前是否需要建立数组?
如果输入01-01-2015它应该改为2015-01-01.
如果输入2015-01-01它应该改为01-01-2015.
我使用SimpleDateFormat但没有得到正确的输出:
//Class to change date dd-MM-yyyy to yyyy-MM-dd and vice versa
public class ChangeDate {
static SimpleDateFormat formatY = new SimpleDateFormat("yyyy-MM-dd");
static SimpleDateFormat formatD = new SimpleDateFormat("dd-MM-yyyy");
//This function change dd-MM-yyyy to yyyy-MM-dd
public static String changeDtoY(String date) {
try {
return formatY.format(formatD.parse(date));
}
catch(Exception e) {
return null;
}
}
//This function change yyyy-MM-dd to dd-MM-yyyy
public static String changeYtoD(String date) {
try {
return formatD.format(formatY.parse(date));
} …Run Code Online (Sandbox Code Playgroud) 我试图使用TranslateAnimation上ImageView,但ImageView根本不会移动.运行项目时没有任何反应.这是我的代码:
import android.app.Activity;
import android.os.*;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
public class MainActivity extends Activity {
ImageView a;
TranslateAnimation pengesat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a = (ImageView) findViewById(R.id.imageView3);
pengesat = new TranslateAnimation( 0.0f, 1.0f, 0.0f, 0.0f );
pengesat.setDuration(5000);
pengesat.setRepeatCount(1);
pengesat.setInterpolator(new AccelerateInterpolator());
Thread myThread= new Thread(new Runnable(){
@Override
public void run() {
a.post(new Runnable() {
@Override
public void run() {
a.startAnimation(pengesat);
}
});
}
});
myThread.start();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的xml代码:
<?xml …Run Code Online (Sandbox Code Playgroud) java android android-animation android-imageview material-design
我声明了一个向量如下:vector<unique_ptr<Worker>> Workers.Worker是一个带有私有字段的基类,name它有两个派生类:Builder和Driver.
我添加到Workers的矢量对象Builder和Driver,然后我想在矢量排序,name使用#include <algorithm>这样的:
sort(Workers.begin(), Workers.end(), cmp_by_name);
bool cmp_by_name(const Worker &a, const Worker &b)
{
return a.getName() < b.getName();
}
Run Code Online (Sandbox Code Playgroud)
但VS编译器说:
错误1错误C2664:'bool(const Worker&,const Worker&)':无法将参数2从'std :: unique_ptr>'转换为'const Worker&'c:\ program files(x86)\ microsoft visual studio 12.0\vc\include\algorithm 3071 1 App
我该如何解决这个错误?
感谢@NathanOliver,@ Rabbid76和这个问题,我把我编辑cmp_by_name成这个表格:
struct cmp_by_name
{
inline bool operator()(const unique_ptr<Worker>& a, const unique_ptr<Worker>& b)
{
return a->getName() < b->getName();
} …Run Code Online (Sandbox Code Playgroud) c++ ×4
dictionary ×3
c++11 ×2
java ×2
jquery ×2
stdmap ×2
android ×1
ckeditor ×1
containers ×1
date ×1
fancybox ×1
fancybox-2 ×1
fckeditor ×1
git ×1
iframe ×1
numpy ×1
polymorphism ×1
set ×1
sorting ×1
stl ×1
tortoisegit ×1
unique-ptr ×1
vector ×1