Your use is fine, if not a little detailed. In this context, constexprthey constmean the same thing. There will be either one (or even both).
Fwiw, std::chrono::hours::period::num 60*60 ( ++ 11 cred: -)).
:
void MainWindow::UpdateDateTimes()
{
constexpr std::chrono::seconds cdtOffsetSecs = std::chrono::hours(-5);
constexpr std::chrono::seconds edtOffsetSecs = std::chrono::hours(-4);
constexpr std::chrono::seconds cetOffsetSecs = std::chrono::hours(2);
QDateTime time( QDateTime::currentDateTimeUtc() );
ui->mTimeLocal->setDateTime( time.toLocalTime() );
ui->mTimeCDT->setDateTime( time.addSecs( cdtOffsetSecs.count() ) );
ui->mTimeEDT->setDateTime( time.addSecs( edtOffsetSecs.count() ) );
ui->mTimeCET->setDateTime( time.addSecs( cetOffsetSecs.count() ) );
}
static. static. , static " ".
, :
void f(int);
void UpdateDateTimes()
{
constexpr std::chrono::seconds cdtOffsetSecs = std::chrono::hours(-5);
constexpr std::chrono::seconds edtOffsetSecs = std::chrono::hours(-4);
constexpr std::chrono::seconds cetOffsetSecs = std::chrono::hours(2);
f(cdtOffsetSecs.count());
}
-O1 ( ) clang++ lib++, :
.globl __Z15UpdateDateTimesv
.align 4, 0x90
__Z15UpdateDateTimesv:
.cfi_startproc
pushq %rbp
Ltmp2:
.cfi_def_cfa_offset 16
Ltmp3:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp4:
.cfi_def_cfa_register %rbp
movl $-18000, %edi
popq %rbp
jmp __Z1fi
.cfi_endproc
:
void UpdateDateTimes2()
{
f(-18000);
}
:
.globl __Z16UpdateDateTimes2v
.align 4, 0x90
__Z16UpdateDateTimes2v:
.cfi_startproc
pushq %rbp
Ltmp7:
.cfi_def_cfa_offset 16
Ltmp8:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp9:
.cfi_def_cfa_register %rbp
movl $-18000, %edi
popq %rbp
jmp __Z1fi
.cfi_endproc
imho , - .: -)