鍍金池/ 問(wèn)答/ C++問(wèn)答
忠妾 回答

boost不是標(biāo)準(zhǔn)庫(kù),但它仍然是庫(kù)。<>就是優(yōu)先搜庫(kù),沒(méi)毛病。
你要是用其他的庫(kù),也得用<>。

冷眸 回答

首先,n<2 類(lèi)似于初始化,F(xiàn)ib(0) = 0, Fib(1) = 1;第一個(gè)return就返回了,不會(huì)執(zhí)行下面的打印。
然后,n>2時(shí),F(xiàn)ib(2) = Fib(1) + Fib(0),會(huì)打印Fib(1)和Fib(0)。
這個(gè)就是斐波那契數(shù)列的一邊表達(dá)式:f(n) = f(n-1) + f(n-2)。

陪我終 回答
"010203".match(/\d{2}/g);

或者

"010203".split(/\B(?=(?:\d{2})+\b)/);

或者

"010203".split(/\B(?=0)/);
離夢(mèng) 回答

看少俠這代碼,RoomBusiness這個(gè)類(lèi)應(yīng)該是以單例模式寫(xiě)的吧,所以?xún)煞N方法沒(méi)區(qū)別

乖乖瀦 回答

vector<int>無(wú)需釋放內(nèi)存,但是vector<string>需要swap釋放
當(dāng)然你會(huì)疑惑 int無(wú)需釋放內(nèi)存,string 也無(wú)需釋放內(nèi)存(會(huì)自動(dòng)析構(gòu)釋放),但是為什么在vector中不一樣?
vector<int>等內(nèi)置類(lèi)型無(wú)需釋放內(nèi)存,自動(dòng)釋放。string類(lèi)型的本質(zhì)是指針,vector<string> ,vector<int*>等指針類(lèi)型需要手動(dòng)swap釋放。

我認(rèn)為使用define的最大價(jià)值在于是否可以將大段的重復(fù)性代碼濃縮為define,后續(xù)使用可能用一個(gè)宏就解決大段的重復(fù)性代碼。比如mfc中的消息映射,成功的將很多重復(fù)性的代碼濃縮為一兩個(gè)宏,雖然mfc本身很復(fù)雜,但是它的宏定義的使用堪稱(chēng)教科書(shū)。其他常用的使用場(chǎng)景比如定義不定長(zhǎng)的函數(shù),你給出的這個(gè)例子就是。比如與操作系統(tǒng)和編譯環(huán)境有關(guān)的,比如__FILE__,__LINE__,DEBUG等。至于你講的可能的代替,我認(rèn)為是定義常量、定義簡(jiǎn)單的函數(shù)等。

別傷我 回答

behavior 屬性只有IE兼容吧? 應(yīng)該要盡量避免使用

哎呦喂 回答

@course.comments.sum{ |cc| cc.comment.length }

淚染裳 回答

&的用意我只知道除了是引用和位址之外,它還有一個(gè)功能就是防止拷貝(比較有效率)。

void swap(int &a, int &b)

void swap(int a, int b)

的差別是一個(gè)是整數(shù)a b的本身,另一個(gè)是整數(shù)a b的副本。如果你使用第二個(gè)swap函數(shù)來(lái)進(jìn)行交換整數(shù)的話,你會(huì)發(fā)現(xiàn)沒(méi)有換到。因?yàn)槟闼幚淼闹皇窃诟北旧线M(jìn)行交換整數(shù)而已,它本身的自己卻沒(méi)有更動(dòng)到。


Box operator+(const Box& b)
    {
        Box box;
        box.length = this->length + b.length;
        box.breadth = this->breadth + b.breadth;
        box.height = this->height + b.height;
        return box;
    }

知道了&的一些概念后,你可能會(huì)問(wèn)為什么 Box& b前面要放 const!
因?yàn)槟阒?&會(huì)改變對(duì)象本身,然后我們只是想用b里面的變數(shù)且不想更動(dòng)到它們,所以前面加const的用意是防止改變對(duì)象!

總結(jié)來(lái)說(shuō),const B &b 達(dá)到了無(wú)副本 + 無(wú)法修改的目的。

如 sserver 日志所示

 15 E0403 17:24:39.589262  4886 Utils.cc:221] unable to request data from: https://127.0.0.1/get_user_id_list?last_id=0, error: Couldn't connect to server
 16 E0403 17:24:39.589727  4886 StratumServer.cc:480] http get request user list fail, url: https://127.0.0.1/get_user_id_list?last_id=0
 17 E0403 17:24:39.589777  4886 StratumServer.cc:547] update user list failure
 18 E0403 17:24:39.589867  4886 StratumServer.cc:776] fail to setup server
 19 F0403 17:24:39.589912  4886 StratumServerMain.cc:171] init failure

參考 sserver.cfg 的注釋?zhuān)阈枰约捍罱ㄒ粋€(gè)網(wǎng)站服務(wù)器(xx.yy),并提供一個(gè)網(wǎng)站接口(/get_user_id_list),然后把網(wǎng)址寫(xiě)入 sserver.cfg 文件的 list_id_api_url 項(xiàng),如下

users = {
    list_id_api_url = "http://xx.yy/get_user_id_list";
};

你可以在本機(jī)搭建一個(gè) apache 或者 nginx 服務(wù)器,然后按照
https://github.com/btccom/btc...
上的說(shuō)明操作便可。

涼心人 回答

select操作不會(huì)造成死鎖。我猜測(cè):update語(yǔ)句有大字段更新,導(dǎo)致事務(wù)時(shí)間較長(zhǎng)(即長(zhǎng)事務(wù)),同時(shí),其他select語(yǔ)句引起update操作,當(dāng)update同一條記錄時(shí),就會(huì)導(dǎo)致死鎖(等待長(zhǎng)事務(wù)的完成)。

情皺 回答

可重入鎖不是這么用的,一般是在面向?qū)ο笾惺褂?,比?/p>

class A:
   def f1(self):
       mutex.acquire()
       try:
           #do something
       finally:
           mutex.release()
   def f2(self):
       mutex.acquire()
       try:
           #do something
       finally:
           mutex.release()

def run1(obj):
    obj.f1()
    obj.f2()
    
def run2(obj):
    obj.f2()
    obj.f1()

obj1 = A()
t1 = threading.Thread(target=run1, args=(obj1, ))
t2 = threading.Thread(target=run2, args=(obj1, ))
t1.start()
t2.start()

調(diào)用順序不同,而且都需要同步的時(shí)候,如果不用遞歸鎖,會(huì)死鎖。如果f1或f2不加鎖,數(shù)據(jù)不同步,報(bào)錯(cuò)

墨小白 回答

sem_init函數(shù)入?yún)⑿枰獋魅虢Y(jié)構(gòu)體地址,即sem_t mutex;
sem_init(&mutex);

還有看到你buffer定義是數(shù)組指針,但感覺(jué)初始化是按照字符數(shù)組初始化的。

不用 inplace (直接分成兩個(gè)數(shù)組排序,再合并) 的話就太簡(jiǎn)單了,要 inplace 的話其實(shí)也可以不用手寫(xiě) iterator,手寫(xiě)一個(gè) reference 的 wrapper 就行了(然后直接調(diào)用任意 常規(guī) inplace 排序算法即可):

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

template <typename T>
class Ref {
  T & t;

public:

  Ref(T & t) : t(t) {
  }

  Ref(Ref & o) : t(o.t) {
  }

  Ref(Ref && o) : t(o.t) {
  }

  Ref & operator = (Ref & o) {
    t = o.t;
    return *this;
  }

  Ref & operator = (Ref && o) {
    t = move(o.t);
    return *this;
  }

  bool operator < (Ref const & o) const {
    return t < o.t;
  }

  friend void swap(Ref & a, Ref & b) {
    using std::swap;
    swap(a.t, b.t);
  }
};

void solution(vector<string> & ret) {
  vector<Ref<string>> a;
  vector<Ref<string>> b;

  for (auto & c : ret) {
    bool numeric = true;
    for (auto const & d : c) {
      if (!isdigit(d)) numeric = false;
    }
    if (numeric) a.emplace_back(c); else b.emplace_back(c);
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  vector<string> v;

  string l;
  getline(cin, l);

  stringstream ss;
  ss << l;

  string s;
  while (ss >> s) {
    v.emplace_back(move(s));
  }

  solution(v);

  bool first = true;
  for (auto const & c : v) {
    if (first) first = false; else cout.put(' ');
    cout << c;
  }
  cout << '\n';
}

測(cè)試:

輸入

2 Banana 1 Apple 3 Pear

輸出

1 Apple 2 Banana 3 Pear

不討囍 回答

你的中文編碼是UTF8的?如果是查看一下你對(duì)應(yīng)的要匹配的中文的UTF8編碼,然后在regex正則表達(dá)式中使用對(duì)應(yīng)的UTF8編碼匹配。

雅痞 回答

你可以裝個(gè)瀏覽器版的插件,就不用裝在本機(jī)了。圖片描述

薄荷綠 回答
//testgo.h
#ifdef __cplusplus
extern "C"{
#endif
extern long calladdr(long addr);
#ifdef __cplusplus
}
#endif
//testgo.cpp
#include "testgo.h"

long calladdr(long addr){
    return addr;
}
//test.go
package main

// #include "testgo.h"
// #cgo LDFLAGS: ${SRCDIR}/testgo.so -lstdc++
import "C"
import "fmt"
import "unsafe"

type Work struct {
    Name string
}

func main() {
    data := &Work{Name: "aaa"}
    ad := C.long(uintptr(unsafe.Pointer(data)))

    addr := C.calladdr(ad)
    newdata := (*Work)(unsafe.Pointer(uintptr(addr)))
    fmt.Println("newdata is", newdata)
}

應(yīng)該可以滿足要求

吃藕丑 回答

locals=6,args(1個(gè)),short x(1個(gè)),double y(2個(gè)),double z(2個(gè))
dstore 4意思是從棧頂彈出2個(gè)字的值,因?yàn)槭莇型的,并把結(jié)果賦給第5和第6個(gè)local位置。