If I have an interface as shown below:
template <typename V, typename K> V get(K key); // Return the value of the key
Does it make sense to "return NULL when the key is not found"? Is there a way to handle the case when the key is not found, except for an exception exception?
Also throwing an exception is the best way to handle a non-existent key?
, V . V int, , return nullptr, int. V - , , nullptr . , nullptr, return ed " " "" nullptr?
V
int
return
nullptr
return , , .
template <typename V, typename K> V * get(K key);
const V *, , .
const V *
optional<T>. Boost, .
optional<T>
, throw , . , , , . , . , , , .
throw
Source: https://habr.com/ru/post/1623330/More articles:Hide title in full screen (AppCompatActivity) - androidCreating a child window without a MVVM frame - c #Using std :: thread in Node.js Addon - c ++Use the GoogleMap API or MapBox Direction API to implement my own navigation in my application. - androidHow can I get the distance, direction, duration from my current location to the next step? - javaSkip property-based plugin execution - mavenCamera2 ImageReader freezes re-capture request - androidHow to get a node that is in front of another? - xmlgrid search with weighted AUC - scikit-learnThe best way to sort a list by reversing the sublist is sortingAll Articles