鍍金池/ 問答/ C++問答
遲月 回答

利用es6的Set吧
求并集,判斷size

const s1 = 'abcsk'
const s2 = 'abnn'
if (new Set(s1).size === new Set(s1 + s2).size) {
    // 說明s2里面只有s1的元素
} else {
    // 說明s2里面含有s1意外的元素
}
小曖昧 回答

有個npm包,就叫ws.js。是個基于 Node.js的WS-*實現(xiàn)。想必就是這玩意兒

維她命 回答

已經(jīng)解決了。。只要在子組件定義的方法里加上this.$nextTick就行了,異步執(zhí)行的原因,子組件還沒渲染完就調(diào)用了方法就會這樣

萢萢糖 回答

找到了,toFixed()會自動四舍五入...

瘋浪 回答

j的回溯只會影響搜索主循環(huán)次數(shù)的上下界([m, 2m]),而不會像你說的使其變成m*n的關(guān)系。

你可以這樣理解,由于m是只增不減的,所以最壞的情況是這樣的:

  1. 每次匹配都會失?。╩保持不變)
  2. 再次匹配也失?。╩+1)

在這種情況下,對于M中的每個字符,實際上都比較了2次,所以一共執(zhí)行了2m次循環(huán)。這是循環(huán)次數(shù)的上限。其他任何情況,都至少有若干次循環(huán)是m直接+1的。

純妹 回答

根據(jù)錯誤是卡到Android 系統(tǒng)變量的問題!

空白格 回答

你在用operator+的時候, 是按值傳入的, 沒有改變part. 而push_back()時, 改變了part, 在第三個ifpart的值與你預(yù)期就不符了, 你把第二個例子都改成string temp = part; temp.push_back(...); __generateP...(..., temp, ...);應(yīng)該也能AC了.

PS: 自己寫代碼時, 別用雙下劃線開頭, 不知道你是從那裏學(xué)來的這個習(xí)慣, 在c++中必須摒棄, 因爲(wèi)這些都是保留字, 是留給標(biāo)準(zhǔn)庫用的, 你一旦起了這樣的名, 就是UB了. 所以窩看py時, 總是非常不爽...

痞性 回答

new is not an operator!

In c++, new and operator are both keywords. new int(x) is a(n) (new-)expression. operator new is a function. new operator in your title is new-expression indeed. new-expression will invoke oeprator new function.

placement new的作用就是在operator new分配好的內(nèi)存上執(zhí)行對象的構(gòu)造,
Yes, that's true. To help you understand, here is a sample:
char* ptr = new char[sizeof(T)]; // ptr use a new-expression(newchar [sizeof(T)] to allocate memory, char is guaranteed to be sizeof 1
T* tptr = new(ptr) T;            // Here is placement new

In a nutshell, placement new will use already allocated memory to construct the object. Where is the already allocated memory from? Either from new expression(free store) or allocated from activation record like int buffer[10], both ok.

那么new operator使用了operator new來申請內(nèi)存之后是使用了placement new嗎?如果沒有話是怎么構(gòu)造的呢?和placement new有關(guān)系嗎?

Above is my answer to your questions

BTW, from the case int buffer[10], we can see pre-new-expression is not a must for placement new(however, note that placement new itself is a new-expression, which will invoke operator new function because all it does is just construct here). If your question is "will placement new always be after operator new/new-expression", it will be a good question.

Update

One year ago, I was confused about how to combine operator new with the constructor then asked a question, FrankHB answered my question: https://tieba.baidu.com/p/508... Now, look back to this question, it is a X-Y question, what really confused me was how does new expression invoke constructor, so it is not related to placement new. Hope it will also inspire you.

Update again

所以我認(rèn)為或許自己和您一年前的疑問相似,內(nèi)存申請和構(gòu)造函數(shù)這兩個過程是如何結(jié)合的呢?
the word combination(結(jié)合) is not properly now(I also make such mistake as said above), let me re-organize my wording:

new expression does two things:

  1. allocate memory
  2. initialization of the object

You and I(one year ago) are both confused about how does compiler initialize the object(via constructor or else) after allocating. Yes, I mentioned compiler, because C++ standard guarantee new will do the two things, but didn't how to, so, its compiler's work. So, it is not c++'s work, just compiler's. Now, we can see the assembly:

struct Foo
{
    Foo(int i) {}
};
int main()
{
    auto *a = new Foo(1);
}  

-O0:

Foo::Foo(int):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        mov     DWORD PTR [rbp-12], esi
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        push    rbx
        sub     rsp, 24
        mov     edi, 1
        call    operator new(unsigned long)
        mov     rbx, rax
        mov     esi, 1
        mov     rdi, rbx
        call    Foo::Foo(int)
        mov     QWORD PTR [rbp-24], rbx
        mov     eax, 0
        add     rsp, 24
        pop     rbx
        pop     rbp
        ret

codes related the new expression is follows: a

    mov     edi, 1
    call    operator new(unsigned long)
    mov     rbx, rax
    mov     esi, 1
    mov     rdi, rbx
    call    Foo::Foo(int)
    mov     QWORD PTR [rbp-24], rbx
    

Now, it is clear enough, right? assemble calls two procedures, oeprator new and Foo::Foo(int)

That's all, cheers!

So, your question is how the two combined?

尛曖昧 回答

為什么不考慮把過濾器全局注冊呢?


更新一波
其實Vue的過濾器是可以傳參數(shù)的,你可以像這樣定義過濾器

Vue.filter('filter', function(val, name){//這是總的過濾器
  console.log(val, name)
    switch(name){//這里通過switch進行匹配
      case 'filter1': 
        return filter1(val);
      case 'filter2': 
        return filter2(val)
    }
})
// 下面的方法才是你具體的某些過濾器的方法
function filter1(val){
  return val +  ': 我是filter1'

}
function filter2(val){
  return val +  ': 我是filter2'
}

然后使用的話,傳過濾器名字進入就行了

<template>
    <div>
        {{'hahaha' | filter(filter)}}
    </div>
</template>

<script>
export default {
    props: ['filter']
}
</script>
柒喵 回答

spring-boot的項目,如果需要“打包給其他項目用“就不能用spring-boot的插件打包,用默認(rèn)的打包
但是這樣之后的jar包是不能java -jar運行的

愛是癌 回答

推薦@pezy 大佬寫的設(shè)計模式專欄。

設(shè)計模式

誮惜顏 回答

1.可以給document的touchmove事件禁止掉就行了

document.querySelector('body').addEventListener('touchmove', function(e) {
        e.preventDefault();
    })

2.如果頁面有部分區(qū)域必須需要滑動,需要用touchmove事件的話,那么可以把那部分的touchmove事件過濾掉

比如我想要以下代碼中的bottom類可以用touchmove事件

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>微信禁止下拉露黑底</title>
</head>
<body>
    <div class="top"></div>
    <div class="bottom"></div>
</body>
</html>

用以下代碼就可以實現(xiàn)

document.querySelector('body').addEventListener('touchmove', function(e) {
    if (!document.querySelector('.bottom').contains(e.target)) {
        e.preventDefault();
    }
})
 

淺淺 回答

*.cpp文件沒有加入CMakeLists.txt中, 檢查一下這個文件吧.

涼心人 回答

在你的這個列子里,你可以在service里寫把商品添加進購物車?yán)锩孢@個接口,以及獲取購物車數(shù)據(jù)(即里面有多少商品),共2個接口。service一般用作component和data通訊,包括發(fā)起HTTP請求調(diào)用API,處理業(yè)務(wù)數(shù)據(jù),操作業(yè)務(wù)邏輯。起到component間數(shù)據(jù)共享的效果

巫婆 回答

select
(select name from user where user.uid = c.uid) as replyer,
(select name from user where user.uid = c.to_uid) as replyed,
c.content
from comment c
where id=1

理解下來數(shù)據(jù)都是在comment表中,只是comment.uid 和 comment.to_uid 需要轉(zhuǎn)義成名稱,
上述sql 有可能提供一些解決思路。

伴謊 回答

const getType = target => Object.prototype.toString.call(target);

安淺陌 回答

我是寫 Java 的,那么如果要用不那么 OO 的方式(我們一般喜歡用日志 slf4j 之類的),那么我會用下面兩種思路:

public static void printTimes(Object obj, int times) {
    String content = obj.toString();
    // 通過新建一個異常來獲取調(diào)用棧信息,不拋出即可。
    String where = new Exception().getStackTrace()[1].getClassName();
    // 后續(xù)省略
}

public interface Printer {

    // 此法需要 Java 8
    // 聲明默認(rèn)方法,想要為某個類加上按次數(shù)打印功能時就 implements Printer
    default void printTimes(Object obj, int times) {
        String where = this.getClass().getSimpleName();
        // 后續(xù)省略
    }

}

事實上新建異常來獲取調(diào)用棧信息可以拿到非常完整的執(zhí)行環(huán)境信息:

所處類 | 所處方法 | 所在文件名稱 | 所在文件行數(shù)

歡迎討論。